比赛 |
2024暑假C班集训5 |
评测结果 |
WAWWWWWWWW |
题目名称 |
任务 |
最终得分 |
10 |
用户昵称 |
darkMoon |
运行时间 |
0.009 s |
代码语言 |
C++ |
内存使用 |
1.17 MiB |
提交时间 |
2024-07-05 10:04:50 |
显示代码纯文本
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define mp make_pair
using namespace std;
//#define fin cin
//#define fout cout
ifstream fin("task.in");
ofstream fout("task.out");
auto mread = [](){
int x;
fin >> x;
return x;
};
const int N = 2005;
int n = mread(), a[N], b[N], s[N][2];
pair<int, int> f[N][2];
signed main(){
for(int i = 1; i <= n; i ++){
a[i] = mread(), b[i] = mread();
s[i][0] = s[i - 1][0] + a[i];
s[i][1] = s[i - 1][1] + b[i];
}
for(int i = 1; i <= n; i ++)
f[i][0] = f[i][1] = mp(LONG_LONG_MAX, 0);
f[0][0] = f[0][1] = mp(0, 0);
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= i; j ++){
int sum = s[i][0] - s[j - 1][0];
int tmp = f[j - 1][0].fi + sum;
f[i][0] = min(f[i][0], mp(tmp, max(f[j - 1][0].se, tmp - a[i])));
tmp = f[j - 1][1].se + sum;
if(tmp >= f[j - 1][1].fi){
f[i][0] = min(f[i][0], mp(tmp, max(f[j - 1][1].fi, tmp - a[i])));
}
if(tmp <= f[j - 1][1].fi){
f[i][1] = min(f[i][1], mp(f[j - 1][1].fi, max(tmp, f[j - 1][1].se)));
}
sum = s[i][1] - s[j - 1][1];
tmp = f[j - 1][1].fi + sum;
f[i][1] = min(f[i][1], mp(tmp, max(f[j - 1][1].se, tmp - b[i])));
tmp = f[j - 1][0].se + sum;
if(tmp >= f[j - 1][0].fi){
f[i][1] = min(f[i][1], mp(tmp, max(f[j - 1][0].fi, tmp - b[i])));
}
if(tmp <= f[j - 1][0].fi){
f[i][0] = min(f[i][0], mp(f[j - 1][0].fi, max(tmp, f[j - 1][0].se)));
}
}
}
fout << min(f[n][0].fi, f[n][1].fi);
}