QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#672346 | #9408. Hero of the Kingdom | REN_REN# | RE | 0ms | 0kb | C++20 | 1.3kb | 2024-10-24 16:32:06 | 2024-10-24 16:32:11 |
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
using i128 = __int128;
int n, k;
const int mod = 998244353;
int p, a, b, q, c, d, m, t;
void solve(){
cin >> p >> a >> b;
cin >> q >> c >> d;
cin >> m >> t;
a += c, b += d;
while(1) {
int i = min(m / p, (t - b) / a);
// if(t < b) break;
// if(m / p >= (t - b) / a) {
// int i = (t - b) / a;
// m += i * (q - p);
// break;
// }
// int i = m / p;
// if(i <= 0) break;
int tmaxc = t / (a * i + b);
int gain = tmaxc * i * (q - p);
if(m + gain >= p * (i + 1)) {
int nd = p * (i + 1) - m;
int ndx = (nd + (q - p) - 1) / (q - p);
int ndc = (ndx + i - 1) / i;
int ndt = a * ndc * i + b * ndc;
// cout << i << ' ' << nd << ' ' << ndx << ' ' << ndc << ' ' << ndt << ' ';
t -= ndt;
m += ndc * (q - p) * i;
// cout << t << ' ' << m << endl;
} else {
m += gain;
break;
}
}
cout << m << '\n';
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int t = 1;
cin >> t;
while(t --){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
3 5 2 3 8 1 5 14 36 5 2 0 8 1 3 17 6 100 1 0 10000 1 0 99 100000