//Challenge: Accepted
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
while (l != r) cout << *l << " ", l++;
cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 9000005
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
const int inf = 1<<30;
int dp[maxn];
int main() {
io
int m;
ll L;
cin >> m >> L;
vector<ll> a(2*m+1), ex(2*m+1);
ll mins = 0, ans = 0;
for (int i = 0;i < 2*m+1;i++) {
cin >> a[i];
if (i == m) ans += a[i], a[i] = 0;
}
for (int i = m+1;i < 2*m+1;i++) {
ll p = min(a[i], L / (i-m));
ans += p;
L -= p * (i-m);
a[i] -= p;
ex[i] = min(a[i], (ll)m);
ex[2 * m - i] = min(p,(ll)m);
}
for (int i = 0;i < 2 * m+1;i++) {
if (i < m) mins += ex[i] * (i - m);
}
for (int i = 0;i < maxn;i++) dp[i] = -inf;
dp[-mins] = 0;
for (int i = 0;i < 2*m+1;i++) {
int d = i - m;
if (i - m == 0) continue;
if (i - m > 0) {
for (int j = 0;j < d;j++) {
deque<int> deq;
for (int k = j;k < maxn;k += d) {
while (deq.size() && (k - deq.front())/d > ex[i]) deq.pop_front();
if (deq.size()) dp[k] = max(dp[k], dp[deq.front()] + (k - deq.front()) / d);
while (deq.size() && dp[k] >= dp[deq.back()] + (k - deq.back())/d) deq.pop_back();
deq.push_back(k);
}
}
} else {
for (int j = 0;j < -d;j++) {
deque<int> deq;
for (int k = maxn-1-j;k >= 0;k += d) {
while (deq.size() && (k - deq.front())/d > ex[i]) deq.pop_front();
if (deq.size()) dp[k] = max(dp[k], dp[deq.front()] - (k - deq.front()) / d);
while (deq.size() && dp[k] >= dp[deq.back()] - (k - deq.back())/d) deq.pop_back();
deq.push_back(k);
}
}
}
}
if (L - mins >= maxn || L - mins < 0 || dp[L - mins] < -maxn) cout << "impossible\n";
else cout << dp[L - mins]+ans << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
335 ms |
35524 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
335 ms |
35524 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1412 ms |
35524 KB |
Output is correct |
2 |
Correct |
4674 ms |
35540 KB |
Output is correct |
3 |
Incorrect |
3546 ms |
35524 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1412 ms |
35524 KB |
Output is correct |
2 |
Correct |
4674 ms |
35540 KB |
Output is correct |
3 |
Incorrect |
3546 ms |
35524 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1412 ms |
35524 KB |
Output is correct |
2 |
Correct |
4674 ms |
35540 KB |
Output is correct |
3 |
Incorrect |
3546 ms |
35524 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
335 ms |
35524 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1412 ms |
35524 KB |
Output is correct |
2 |
Correct |
4674 ms |
35540 KB |
Output is correct |
3 |
Incorrect |
3546 ms |
35524 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
335 ms |
35524 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1412 ms |
35524 KB |
Output is correct |
2 |
Correct |
4674 ms |
35540 KB |
Output is correct |
3 |
Incorrect |
3546 ms |
35524 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
335 ms |
35524 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |