#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
string _reset = "\u001b[0m", _yellow = "\u001b[33m", _bold = "\u001b[1m";
void DBG() { cerr << "]" << _reset << endl; }
template<class H, class...T> void DBG(H h, T ...t) {
cerr << to_string(h);
if(sizeof ...(t)) cerr << ", ";
DBG(t...);
}
#ifdef CHEISSMART
#define debug(...) cerr << _yellow << _bold << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define debug(...)
#endif
const int INF = 1e9 + 7, mxM = 101;
template<class T> void cmax(T& a, T b) { a = max(a, b); }
int m, l;
ll a[mxM * 2], b[mxM * 2];
signed main()
{
IO_OP;
cin >> m >> l;
ll tot = 0, ans = 0;
for(int i = -m; i <= m; i++) {
cin >> a[i + m];
tot += a[i + m] * i;
}
if(tot < l) {
tot = -tot;
l = -l;
for(int i = 0; i < m; i++)
swap(a[i], a[2 * m - i]);
}
tot = 0;
for(int i = -m; i <= 0; i++) {
tot += a[i + m] * i;
b[i + m] = a[i + m];
ans += b[i + m];
}
if(tot > l) {
cout << "impossible\n";
return 0;
}
for(int i = 1; i <= m; i++) {
assert(tot <= l);
b[i + m] = min((l - tot) / i, a[i + m]);
tot += b[i + m] * i;
ans += b[i + m];
}
assert(tot <= l);
if(tot + mxM < l) {
cout << "impossible\n";
return 0;
}
int C = mxM * mxM * 2;
vi dp(C * 2, -INF);
dp[0 + C] = 0;
for(int i = -m; i <= m; i++) {
vi ndp(C * 2, -INF);
for(int delta = -2 * m - 1; delta <= 2 * m + 1; delta++) {
if(b[i + m] + delta < 0 || b[i + m] + delta > a[i + m]) continue;
for(int j = 0; j < C * 2; j++) if(0 <= j + delta * i && j + delta * i < C * 2) {
cmax(ndp[j + delta * i], dp[j] + delta);
}
}
swap(dp, ndp);
}
ans += dp[l - tot + C];
if(ans < 0) cout << "impossible\n";
else cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
596 KB |
Output is correct |
2 |
Correct |
2 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
5 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
121 ms |
596 KB |
Output is correct |
7 |
Correct |
50 ms |
596 KB |
Output is correct |
8 |
Correct |
117 ms |
620 KB |
Output is correct |
9 |
Correct |
241 ms |
596 KB |
Output is correct |
10 |
Correct |
12 ms |
596 KB |
Output is correct |
11 |
Correct |
10 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
596 KB |
Output is correct |
2 |
Correct |
2 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
5 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
121 ms |
596 KB |
Output is correct |
7 |
Correct |
50 ms |
596 KB |
Output is correct |
8 |
Correct |
117 ms |
620 KB |
Output is correct |
9 |
Correct |
241 ms |
596 KB |
Output is correct |
10 |
Correct |
12 ms |
596 KB |
Output is correct |
11 |
Correct |
10 ms |
596 KB |
Output is correct |
12 |
Correct |
2 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
4 ms |
596 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
121 ms |
624 KB |
Output is correct |
18 |
Correct |
55 ms |
596 KB |
Output is correct |
19 |
Correct |
130 ms |
636 KB |
Output is correct |
20 |
Correct |
202 ms |
620 KB |
Output is correct |
21 |
Correct |
12 ms |
596 KB |
Output is correct |
22 |
Correct |
12 ms |
596 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
463 ms |
628 KB |
Output is correct |
25 |
Correct |
160 ms |
596 KB |
Output is correct |
26 |
Correct |
893 ms |
620 KB |
Output is correct |
27 |
Correct |
826 ms |
620 KB |
Output is correct |
28 |
Correct |
24 ms |
596 KB |
Output is correct |
29 |
Correct |
26 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
596 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 |
5 ms |
596 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 |
5 ms |
596 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 |
2 ms |
596 KB |
Output is correct |
2 |
Correct |
2 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
5 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
121 ms |
596 KB |
Output is correct |
7 |
Correct |
50 ms |
596 KB |
Output is correct |
8 |
Correct |
117 ms |
620 KB |
Output is correct |
9 |
Correct |
241 ms |
596 KB |
Output is correct |
10 |
Correct |
12 ms |
596 KB |
Output is correct |
11 |
Correct |
10 ms |
596 KB |
Output is correct |
12 |
Correct |
5 ms |
596 KB |
Output is correct |
13 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
596 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 |
2 ms |
596 KB |
Output is correct |
2 |
Correct |
2 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
5 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
121 ms |
596 KB |
Output is correct |
7 |
Correct |
50 ms |
596 KB |
Output is correct |
8 |
Correct |
117 ms |
620 KB |
Output is correct |
9 |
Correct |
241 ms |
596 KB |
Output is correct |
10 |
Correct |
12 ms |
596 KB |
Output is correct |
11 |
Correct |
10 ms |
596 KB |
Output is correct |
12 |
Correct |
2 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
4 ms |
596 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
121 ms |
624 KB |
Output is correct |
18 |
Correct |
55 ms |
596 KB |
Output is correct |
19 |
Correct |
130 ms |
636 KB |
Output is correct |
20 |
Correct |
202 ms |
620 KB |
Output is correct |
21 |
Correct |
12 ms |
596 KB |
Output is correct |
22 |
Correct |
12 ms |
596 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
463 ms |
628 KB |
Output is correct |
25 |
Correct |
160 ms |
596 KB |
Output is correct |
26 |
Correct |
893 ms |
620 KB |
Output is correct |
27 |
Correct |
826 ms |
620 KB |
Output is correct |
28 |
Correct |
24 ms |
596 KB |
Output is correct |
29 |
Correct |
26 ms |
596 KB |
Output is correct |
30 |
Correct |
5 ms |
596 KB |
Output is correct |
31 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
32 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
596 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 |
2 ms |
596 KB |
Output is correct |
2 |
Correct |
2 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
5 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
121 ms |
596 KB |
Output is correct |
7 |
Correct |
50 ms |
596 KB |
Output is correct |
8 |
Correct |
117 ms |
620 KB |
Output is correct |
9 |
Correct |
241 ms |
596 KB |
Output is correct |
10 |
Correct |
12 ms |
596 KB |
Output is correct |
11 |
Correct |
10 ms |
596 KB |
Output is correct |
12 |
Correct |
2 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
4 ms |
596 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
121 ms |
624 KB |
Output is correct |
18 |
Correct |
55 ms |
596 KB |
Output is correct |
19 |
Correct |
130 ms |
636 KB |
Output is correct |
20 |
Correct |
202 ms |
620 KB |
Output is correct |
21 |
Correct |
12 ms |
596 KB |
Output is correct |
22 |
Correct |
12 ms |
596 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
463 ms |
628 KB |
Output is correct |
25 |
Correct |
160 ms |
596 KB |
Output is correct |
26 |
Correct |
893 ms |
620 KB |
Output is correct |
27 |
Correct |
826 ms |
620 KB |
Output is correct |
28 |
Correct |
24 ms |
596 KB |
Output is correct |
29 |
Correct |
26 ms |
596 KB |
Output is correct |
30 |
Correct |
5 ms |
596 KB |
Output is correct |
31 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
32 |
Halted |
0 ms |
0 KB |
- |