제출 #1120767

#제출 시각아이디문제언어결과실행 시간메모리
1120767vjudge1Uplifting Excursion (BOI22_vault)C++17
0 / 100
1 ms508 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 << "impossible\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...