#45057: 不是最佳解但可以參考看看(C++)


ethanlai588@gmail.com (刷題時才發現唯一的女友是電腦)

學校 : 新北市私立竹林高級中學
編號 : 254296
來源 : [114.136.203.122]
最後登入時間 :
2025-09-20 12:17:38

#include <iostream>
#include <vector>
using namespace std;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a = 0, b = 0, n = 0;
    int total = 0;
    cin >> a >> b >> n;
    vector<int> v1;
    for (int i = 0; i < n; i++){
        int tmp = 0;
        cin >> tmp;
        v1.push_back(tmp);
    }
    for (int j = 0; j < n; j++){
        int sec = v1[j] % (a + b);
        if (sec < a)
            continue;
        else if (sec == a){
            total += b;
            continue;
        }
        else if (sec > a){
            total += b - (sec - a);
            continue;
        }
    }
    cout << total;
    return 0;
}