#pragma GCC optimize("Ofast,O3,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define MP make_pair
const int N = 100500;
long long solve(){
int m; ll L;
cin >> m >> L;
if (L < 0) return -1;
vector<ll> a(m + 1);
vector<int> b;
for (int i = -m; i <= m; i++){
ll x;
cin >> x;
if (i < 0) continue;
a[i] = x;
if (i > 0) {
ll mn = min((ll) 2 * m / i, a[i]);
while (mn--) b.push_back(i);
}
}
const int LIM = accumulate(all(b), 0) + 1;
vector<int> dp(LIM, 1e9);
dp[0] = 0;
for (int x : b) {
for (int i = LIM - 1; i >= x; i--) {
dp[i] = min(dp[i], dp[i - x] + 1);
}
}
if (L == 0) return a[0];
if (L >= LIM) return -1;
ll ans = -1;
ll tot = 0, cnt = a[0];
for (int i = 1; i <= m; i++){
assert(tot <= L);
ll x = min(a[i], (L - tot) / i);
tot += x * i;
cnt += x;
if (tot == L){
ans = max(ans, cnt);
} else if (a[i] > x){
int add = 0;
for (ll del = tot + i - L; del < LIM; del += i){
add++;
if (add <= a[i] - x) ans = max(ans, cnt - dp[del] + add);
}
}
}
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
long long result = solve();
if (result != -1){
cout << result << endl;
} else {
cout << "impossible" << endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |