【題解】Codeforces 1413E. Solo mid Oracle

【題目敘述】http://codeforces.com/contest/1413/problem/E

#include <bits/stdc++.h>
using namespace std;
 
long long t, a, b, c, d;
 
int main(){
    cin >> t;
    while (t--){
        cin >> a >> b >> c >> d;
        if (a > b*c){
            cout << -1 << "\n";
            continue;
        }
        long long i = a/(d*b)+1;
        cout << i*a-((i*i*d-i*d)/2)*b << "\n";
    }
}
分享本文 Share with friends