#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<pii> vpii;
typedef vector<ll> vi;
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
const int MAXSIZE = 1000000;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
ll M, L;
cin >> M >> L;
vi A(2 * M + 1);
for (int i = 0; i < sz(A); ++i)
cin >> A[i];
vi dp(MAXSIZE, -1);
vi dp2(MAXSIZE, -1);
ll center = MAXSIZE / 2;
dp[center] = A[M];
for (int foo = 0; foo < 2; ++foo)
{
reverse(all(A)), reverse(all(dp)), reverse(all(dp2));
for (ll m = 1; m <= M; ++m)
{
ll maxNum = A[m + M];
for (ll r = 0; r < m; ++r)
{
multiset<ll> stuff;
for (int i = 0; m * i + r < sz(dp); ++i)
{
int idx = m * i + r;
if (dp[idx] != -1)
stuff.insert(dp[idx] - i);
if (!stuff.empty())
dp2[idx] = i + *stuff.rbegin();
if (idx >= maxNum * m && dp[idx - maxNum * m] != -1)
stuff.erase(dp[idx - maxNum * m] - (i - maxNum));
}
}
swap(dp2, dp);
}
}
ll ans = -1;
if (0 <= center + L && center + L < sz(dp))
ans = dp[center + L];
if (ans == -1)
cout << "impossible\n";
else
cout << ans << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
15956 KB |
Output is correct |
2 |
Correct |
26 ms |
15956 KB |
Output is correct |
3 |
Correct |
15 ms |
15956 KB |
Output is correct |
4 |
Correct |
75 ms |
15972 KB |
Output is correct |
5 |
Correct |
807 ms |
15988 KB |
Output is correct |
6 |
Incorrect |
818 ms |
15976 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
15956 KB |
Output is correct |
2 |
Correct |
26 ms |
15956 KB |
Output is correct |
3 |
Correct |
15 ms |
15956 KB |
Output is correct |
4 |
Correct |
75 ms |
15972 KB |
Output is correct |
5 |
Correct |
807 ms |
15988 KB |
Output is correct |
6 |
Incorrect |
818 ms |
15976 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
76 ms |
15976 KB |
Output is correct |
2 |
Incorrect |
1608 ms |
21924 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
76 ms |
15976 KB |
Output is correct |
2 |
Incorrect |
1608 ms |
21924 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
76 ms |
15976 KB |
Output is correct |
2 |
Incorrect |
1608 ms |
21924 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
15956 KB |
Output is correct |
2 |
Correct |
26 ms |
15956 KB |
Output is correct |
3 |
Correct |
15 ms |
15956 KB |
Output is correct |
4 |
Correct |
75 ms |
15972 KB |
Output is correct |
5 |
Correct |
807 ms |
15988 KB |
Output is correct |
6 |
Incorrect |
818 ms |
15976 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
76 ms |
15976 KB |
Output is correct |
2 |
Incorrect |
1608 ms |
21924 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
15956 KB |
Output is correct |
2 |
Correct |
26 ms |
15956 KB |
Output is correct |
3 |
Correct |
15 ms |
15956 KB |
Output is correct |
4 |
Correct |
75 ms |
15972 KB |
Output is correct |
5 |
Correct |
807 ms |
15988 KB |
Output is correct |
6 |
Incorrect |
818 ms |
15976 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
76 ms |
15976 KB |
Output is correct |
2 |
Incorrect |
1608 ms |
21924 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
15956 KB |
Output is correct |
2 |
Correct |
26 ms |
15956 KB |
Output is correct |
3 |
Correct |
15 ms |
15956 KB |
Output is correct |
4 |
Correct |
75 ms |
15972 KB |
Output is correct |
5 |
Correct |
807 ms |
15988 KB |
Output is correct |
6 |
Incorrect |
818 ms |
15976 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |