이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// Bolatulu
#include <bits/stdc++.h>
// #include <art.h>
/*
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
*/
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
#define pb push_back
#define eb emplace_back
#define ins insert
#define F first
#define S second
#define md (tl+tr)/2
#define TL v+v,tl,md
#define TR v+v+1,md+1,tr
#define Tl t[v].l,tl,md
#define Tr t[v].r,md+1,tr
#define all(x) (x).begin(),(x).end()
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define int long long
// #define file(s) freopen(s".in", "r", stdin); freopen(s".out", "w", stdout);
using namespace std;
int binpow(int a,int n,int M) {
if (n==0)
return 1;
if (n%2!=0)
return (a * binpow(a,n-1,M))%M;
int z=binpow(a,n/2,M);
return (z*z)%M;
}
const ll INF = 1e18+7;
const int N = 5e3+7;
int m,l,a[N],b[N],dp[303][505];
void solve() {
cin >> m >> l;
int s=0,ans;
for (int i=m;i>=1;i--) {
cin >> b[i];
s-=b[i]*i;
}
cin >> ans;
for (int i=1;i<=m;i++) {
cin >> a[i];
s+=a[i]*i;
ans+=a[i]+b[i];
}
s-=l;
int x=500;
for (int i=m;i>=1 and abs(s)>=x;i--) {
int z;
if (s>0) {
z=min((s-x)/i+1,a[i]);
a[i]-=z;
ans-=z;
s-=z*i;
} else {
z=min((x-s)/i+1,b[i]);
b[i]-=z;
ans-=z;
s+=z*i;
}
}
for (int i=0;i<=x;i++)
dp[0][i]=INF;
dp[0][abs(s)]=0;
if (s<0) {
for (int i=1;i<=m;i++)
swap(a[i],b[i]);
}
for (int i=1;i<=m;i++) {
for (int j=0;j<=x;j++) {
dp[i][j]=INF;
for (int k=0;k<=a[i] and j+k*i<=x;k++)
dp[i][j]=min(dp[i-1][j+k*i]+k,dp[i][j]);
for (int k=0;k<=b[i] and j-k*i>=0;k++)
dp[i][j]=min(dp[i-1][j-k*i]+k,dp[i][j]);
}
}
if (dp[m][0]==INF)
cout << "impossible";
else
cout << ans-dp[m][0];
}
signed main() {
// file("jenga");
ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
int test = 1;
// cin >> test;
while (test--) {
solve();
if (test)
cout << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |