#include<bits/stdc++.h>
#define MAXN 3007
using namespace std;
int n,m,maxx;
long long pref[MAXN][MAXN],dp[MAXN][MAXN][2];
bool li[MAXN][MAXN][2];
long long prefmax[MAXN],prefmax2[MAXN];
long long suffmax[MAXN],suffmax2[MAXN];
long long max_weights(int N, int M,vector<int> X,vector<int> Y,vector<int> W){
n=N; m=M;
for(int i=0;i<m;i++){
pref[X[i]+1][Y[i]+1]+=W[i];
}
for(int i=1;i<=n;i++){
for(int f=1;f<=n;f++){
pref[i][f]=pref[i][f]+pref[i][f-1];
}
}
for(int pos=1;pos<=n;pos++){
for(int last=0;last<=n;last++){
prefmax[last]=dp[pos-1][last][1]-pref[pos][last];
if(last>0)prefmax[last]=max(prefmax[last],prefmax[last-1]);
prefmax2[last]=dp[pos-1][last][0];
if(last>0)prefmax2[last]=max(prefmax2[last],prefmax2[last-1]);
}
for(int last=n;last>=0;last--){
suffmax[last]=dp[pos-1][last][0]+pref[pos+1][last];
suffmax[last]=max(suffmax[last],suffmax[last+1]);
suffmax2[last]=dp[pos-1][last][0];
suffmax2[last]=max(suffmax2[last],suffmax2[last+1]);
}
for(int last=0;last<=n;last++){
for(int flag=0;flag<2;flag++){
dp[pos][last][flag]=max(dp[pos][last][flag],prefmax[last]+pref[pos][last]);
dp[pos][last][flag]=max(dp[pos][last][flag],prefmax2[last]);
if(flag==0)dp[pos][last][flag]=max(dp[pos][last][flag],suffmax[last+1]-pref[pos+1][last]);
dp[pos][last][flag]=max(dp[pos][last][flag],prefmax2[last+1]);
}
}
}
return dp[n][0][0];
}
/*
int main(){
cout<<max_weights(5, 4, {0, 1, 4, 3}, {2, 1, 4, 3}, {5, 2, 1, 3})<<"\n";
}
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
678 ms |
148032 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Runtime error |
712 ms |
152044 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
722 ms |
143848 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
308 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
2004 KB |
Output is correct |
10 |
Correct |
4 ms |
4948 KB |
Output is correct |
11 |
Correct |
2 ms |
2108 KB |
Output is correct |
12 |
Correct |
3 ms |
4820 KB |
Output is correct |
13 |
Correct |
1 ms |
980 KB |
Output is correct |
14 |
Correct |
3 ms |
4820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
308 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
2004 KB |
Output is correct |
10 |
Correct |
4 ms |
4948 KB |
Output is correct |
11 |
Correct |
2 ms |
2108 KB |
Output is correct |
12 |
Correct |
3 ms |
4820 KB |
Output is correct |
13 |
Correct |
1 ms |
980 KB |
Output is correct |
14 |
Correct |
3 ms |
4820 KB |
Output is correct |
15 |
Correct |
3 ms |
4820 KB |
Output is correct |
16 |
Correct |
1 ms |
1096 KB |
Output is correct |
17 |
Correct |
13 ms |
6076 KB |
Output is correct |
18 |
Correct |
13 ms |
6612 KB |
Output is correct |
19 |
Correct |
14 ms |
6604 KB |
Output is correct |
20 |
Correct |
13 ms |
6612 KB |
Output is correct |
21 |
Correct |
12 ms |
6588 KB |
Output is correct |
22 |
Correct |
22 ms |
8392 KB |
Output is correct |
23 |
Correct |
5 ms |
5204 KB |
Output is correct |
24 |
Correct |
10 ms |
6012 KB |
Output is correct |
25 |
Correct |
3 ms |
4820 KB |
Output is correct |
26 |
Correct |
5 ms |
5192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
308 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
2004 KB |
Output is correct |
10 |
Correct |
4 ms |
4948 KB |
Output is correct |
11 |
Correct |
2 ms |
2108 KB |
Output is correct |
12 |
Correct |
3 ms |
4820 KB |
Output is correct |
13 |
Correct |
1 ms |
980 KB |
Output is correct |
14 |
Correct |
3 ms |
4820 KB |
Output is correct |
15 |
Correct |
3 ms |
4820 KB |
Output is correct |
16 |
Correct |
1 ms |
1096 KB |
Output is correct |
17 |
Correct |
13 ms |
6076 KB |
Output is correct |
18 |
Correct |
13 ms |
6612 KB |
Output is correct |
19 |
Correct |
14 ms |
6604 KB |
Output is correct |
20 |
Correct |
13 ms |
6612 KB |
Output is correct |
21 |
Correct |
12 ms |
6588 KB |
Output is correct |
22 |
Correct |
22 ms |
8392 KB |
Output is correct |
23 |
Correct |
5 ms |
5204 KB |
Output is correct |
24 |
Correct |
10 ms |
6012 KB |
Output is correct |
25 |
Correct |
3 ms |
4820 KB |
Output is correct |
26 |
Correct |
5 ms |
5192 KB |
Output is correct |
27 |
Correct |
189 ms |
212300 KB |
Output is correct |
28 |
Correct |
63 ms |
26820 KB |
Output is correct |
29 |
Correct |
251 ms |
224772 KB |
Output is correct |
30 |
Correct |
249 ms |
224892 KB |
Output is correct |
31 |
Correct |
258 ms |
224876 KB |
Output is correct |
32 |
Correct |
70 ms |
23904 KB |
Output is correct |
33 |
Correct |
248 ms |
224892 KB |
Output is correct |
34 |
Correct |
246 ms |
224844 KB |
Output is correct |
35 |
Correct |
203 ms |
216964 KB |
Output is correct |
36 |
Correct |
244 ms |
224736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
722 ms |
143848 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
678 ms |
148032 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |