#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef pair<int,int> pi;
typedef vector <int> vi;
typedef vector <pi> vpi;
typedef pair<pi, ll> pii;
typedef set <ll> si;
typedef long double ld;
#define f first
#define s second
#define mp make_pair
#define FOR(i,s,e) for(int i=s;i<=int(e);++i)
#define DEC(i,s,e) for(int i=s;i>=int(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define maxn 311
#define INF (ll)(1e18+10)
#define MOD 998244353
typedef pair <vi, int> pvi;
typedef pair <int,pi> ipi;
typedef vector <pii> vpii;
typedef pair <pi,pi> pipi;
int dp[2][maxn*maxn*4];
int A[maxn*2];
int M,L;
int32_t main(){
fast;
cin >> M >> L;
FOR(i,0,2*M) cin >> A[i];
vector <pii> v;
int ans = 0,sm=0;
FOR(i,M,2*M) if (sm <= L){
int x = INF;
if (i != M){
x = (L - sm) / (i - M);
}
x = min(x, A[i]);
sm += x * (i-M);
A[i] -= x;
v.pb(pii(pi(-(i-M), x), -1));
ans += x;
assert(sm <= L+M);
if (A[i] > 0 && sm < L){
sm += i - M; A[i]--; ans++;
v.pb(pii(pi(-(i-M),1),-1));
assert(sm <= L + M && sm >= L);
break;
}
}
//cout << sm << ' ' << ans << '\n';
if (sm < L){
cout << "impossible"; return 0;
}
FOR(i,0,2*M) v.pb(pii(pi(i-M, A[i]), 1));
vpi v2;
aFOR(i,v){
int x = min(2 * M, i.f.s);
for (int k = 0; (1 << k) <= x; k++){
v2.pb(pi((1<<k) * i.f.f, (1<<k)*i.s));
x -= (1 << k);
}
if (x > 0) v2.pb(pi(x * i.f.f, x*i.s));
}
FOR(i,0,4*M*M) dp[0][i] = -INF;
dp[0][M] = 0;
aFOR(i,v2){
FOR(j,0,4*M*M) if (j - i.f >= 0 && j - i.f <= 4*M*M) dp[1][j] = max(dp[0][j], dp[0][j-i.f] + i.s);
FOR(j,0,4*M*M) dp[0][j] = dp[1][j];
}
ans += dp[0][L-sm+M];
if (ans < 0) cout << "impossible";
else cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |