Submission #1120777

#TimeUsernameProblemLanguageResultExecution timeMemory
1120777vjudge1Uplifting Excursion (BOI22_vault)C++17
0 / 100
1 ms512 KiB
#include <bits/stdc++.h> using namespace std; int n, q; long long L; long long b[100100]; long long a[100100]; long long f[100100]; void solve() { cin >> n >> L; for(int i = n; i >= 1; i--) { cin >> b[i]; } long long ex; cin >> ex; //L *= -1; for(int i = 1; i <= n; i++) { cin >> a[i]; L += b[i] * i; ex += b[i]; b[i] += a[i]; } long long c = L; if(c < 0) { cout << "impossible"; return; } for(int i = n; i >= 1; i--) { long long d = min(c/i, b[i]); c -= d * i; } if(c > 0) { cout << "impossible"; return; } c = L; for(int i = 1; i <= n; i++) { long long d = min(c/i, a[i]); f[i] = d; c -= d * i; ex += d; } for(int i = n; i >= 1; i--) { long long d = min(min(c/i, a[i]), b[i] - f[i]); f[i] += d; c -= d * i; ex -= d; } for(int i = n; i >= 1; i--) { long long d = min(c/i,b[i] - f[i]); f[i] += d; c -= d * i; ex -= d; } if(c == 0) { cout << ex << "\n"; } else { cout << ex-1 << "\n"; } } int main() { solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...