This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |