QOJ22910 又一道纸笔问题
Difficulty:Cyan。
题目。
显然我们是可以每次进行单点操作的,也就是说答案上界就是
::::info[代码]
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 1000006
ll ans;
int n,m,a[N];
#define get(i,j) ((i-1)*m+j)
#define min(A,B) ((A)<(B)?(A):(B))
int main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin >> n >> m;
for(int i = 1,now = 1;i <= n;++i){
for(int j = 1;j <= m;++j,++now){
cin >> a[now];
ans += a[now];
}
}
for(int j = 2;j <= m;++j){
ll now = 0;
for(int i = 1,fr,to;i <= n;++i){
fr = get(i,j-1),to = get(i,j);
now += a[fr],ans -= min(now,a[to]);
now -= min(now,a[to]);
}
}
cout << ans;
return 0;
}
::::