QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#134099 | #4931. Comic Binge | ShG | WA | 1ms | 3660kb | C++14 | 2.8kb | 2023-08-03 02:34:29 | 2023-08-03 02:34:33 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#define rep(a, b, c) for(int (a)=(b);(a)<=(c);(a)++)
#define per(a, b, c) for(int (a)=(b);(a)>=(c);(a)--)
#define mset(var, val) memset(var,val,sizeof(var))
#define ll long long
#define int ll
#define fi first
#define se second
#define no "NO\n"
#define yes "YES\n"
#define pb push_back
#define endl "\n"
#define pii pair<int,int>
#define pll pair<ll,ll>
#define dbg(x...) do{cout<<#x<<" -> ";err(x);}while (0)
void err() { cout << '\n'; }
template<class T, class... Ts>
void err(T arg, Ts... args) {
cout << arg << ' ';
err(args...);
}
const int N = 1000 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int P = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1.0);
int suf[N],a[N],b[N],aa[N],bb[N],c[N];
pii dp[N];//fi val;se shengyu
void solve() {
int n;
cin>>n;
rep(i,1,n){
cin>>a[i];
}
rep(i,1,n){
cin>>b[i];
}
int sum=b[1];
aa[1]=b[1];
bb[1]=b[1]+a[1];
rep(i,2,n){
sum+=b[i];
aa[i]=max(bb[i-1],sum);
bb[i]=aa[i]+a[i];
}
suf[0]=suf[n+1]=0;
per(i,n,1){
suf[i]=suf[i+1]+(aa[i]-bb[i-1]);
}
// suf[1]=0;
rep(i,1,n) {
c[i] = min(b[i], suf[i]);
}
c[1]=0;
dp[n].fi=min(suf[n],c[n]),dp[n].se=max(0ll,suf[n]-c[n]);
// dbg(n,dp[n].fi,suf[n],c[n]);
per(i,n-1,1){
// dp[i].fi=min(suf[i],c[i]),dp[i].se=max(0ll,suf[i]-c[i]);
// dbg(suf[i],c[i],dp[i].fi,dp[i].se);
dp[i].fi=dp[i+1].fi,dp[i].se=dp[i+1].se+suf[i]-suf[i+1];
// dbg(i,dp[i].fi,dp[i].se);
rep(j,i+2,n){
if(dp[i].fi<=dp[j].fi+min(dp[j].se+suf[i]-suf[j],c[i])){
if(max(0ll,dp[j].se+suf[i]-suf[j]-c[i])>=dp[i].se){
dp[i].se=max(0ll,dp[j].se+suf[i]-suf[j]-c[i]);
}
dp[i].fi=dp[j].fi+min(dp[j].se+suf[i]-suf[j],c[i]);
}
// dbg(i,j,dp[i].fi,dp[i].se);
}
// dbg(i,dp[i].fi,dp[i].se);
// cout<<endl;
}
cout<<bb[n]-dp[1].fi<<endl;
}
signed main() {
IOS;
int T = 1;
// cin >> T;
while (T--) {
solve();
}
return 0;
}
/*
100
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
6 1 10 10 5 1 9 8 6 7 5 5 4 6 10 5 6 7 3 8 6 3 3 9 3 6 2 9 7 10 8 5 4 8 5 6 8 5 1 4 4 6 4 4 6 8 9 3 1 3 9 6 6 4 6 8 10 6 2 1 3 8 3 3 5 10 6 5 8 8 1 8 5 7 10 3 5 2 9 8 2 3 3 3 8 7 7 10 5 6 7 4 8 1 9 9 5 7 7 8
7
1 1 1 1 1 1 1
6 10 5 6 7 3 8
*/
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3660kb
input:
6 3 1 1 1 1 2 1 5 3 3 7 4
output:
14
result:
wrong answer 1st lines differ - expected: '13', found: '14'