#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define S second
#define F first
long long max_weights(int n,int m,vector<int> X,vector<int> Y,vector<int> W) {
vector<vll> v (n+5,vll {-1}), w(n+5,vll {0});
vector<vpll> la (n+5,vpll {{-1,0}});
ll r=0;
for(int i=0;i<m;i++){
la[X[i]].push_back({Y[i],0});
la[X[i]+1].push_back({Y[i],W[i]});
la[X[i]+2].push_back({Y[i],0});
}
for(int i=0;i<=n;i++){
sort(la[i].begin(),la[i].end());
for(int j=1;j<la[i].size();j++){
v[i].push_back(la[i][j].F);
w[i].push_back(la[i][j].S);
w[i][j]+=w[i][j-1];
}
}
vll t1{{}},t2{{}},t3{{}},t4{{}};
vll h2[2]={{},{}},h1[2]={{0},{0}};
for(int i=1;i<=n;i++){
t1=h1[0];
for(int j=0;j<h1[0].size();j++){
t1[j]=t1[j]-w[i-1][j];
if(j>0)t1[j]=max(t1[j],t1[j-1]);
}
t2=h2[1];
for(int j=0;j<h2[0].size();j++){
if(j>0)t2[j]=max(t2[j],t2[j-1]);
}
t3=h2[1];
for(int j=h2[0].size()-1;j>=0;j--){
t3[j]=t3[j]+w[i-1][j];
if(j+1<h2[0].size())t3[j]=max(t3[j],t3[j+1]);
}
t4=h1[1];ll p=-1;
for(int j=h1[1].size()-1;j>=0;j--){
while(p+1<v[i].size() && v[i][p+1]<=v[i-1][j])p++;
t4[j]=t4[j]+w[i][p];
if(j+1<h1[1].size())t4[j]=max(t4[j],t4[j+1]);
}
ll p1=-1,p2=-1;
vll h[2]={{},{}};
for(int j=0;j<v[i].size();j++){
ll dp[2]={0,0};
// cerr<<i<<" "<<j<<"->"<<v[i][j]<<":\n";
if(i>=2){
while(p1+1<v[i-1].size() && v[i-1][p1+1]<=v[i][j])p1++;
while(p2+1<v[i-2].size() && v[i-1][p2+1]<=v[i][j])p2++;
if(p1>-1) dp[0]=max(dp[0],t1[p1]+w[i-1][p1]);
if(p2>-1) dp[0]=max(dp[0],t2[p2]+w[i-1][p1]);
if(p2<v[i-2].size()-1)dp[0]=max(dp[0],t3[p2+1]);
dp[1]=dp[0];
if(p1<v[i-1].size()-1)dp[1]=max(dp[1],t4[p2+1]-w[i][j]);
}
//cerr<<dp[0]<<" "<<dp[1]<<"\n";
h[0].push_back(dp[0]);
h[1].push_back(dp[1]);
r=max(h[0].back(),max(r,h[1].back()));
}
h2[0]=h1[0];h1[0]=h[0];
h2[1]=h1[1];h1[1]=h[1];
}
return r;
}
Compilation message
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:20:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | for(int j=1;j<la[i].size();j++){
| ~^~~~~~~~~~~~~
fish.cpp:30:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for(int j=0;j<h1[0].size();j++){
| ~^~~~~~~~~~~~~
fish.cpp:35:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for(int j=0;j<h2[0].size();j++){
| ~^~~~~~~~~~~~~
fish.cpp:41:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | if(j+1<h2[0].size())t3[j]=max(t3[j],t3[j+1]);
| ~~~^~~~~~~~~~~~~
fish.cpp:45:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | while(p+1<v[i].size() && v[i][p+1]<=v[i-1][j])p++;
| ~~~^~~~~~~~~~~~
fish.cpp:47:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | if(j+1<h1[1].size())t4[j]=max(t4[j],t4[j+1]);
| ~~~^~~~~~~~~~~~~
fish.cpp:51:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for(int j=0;j<v[i].size();j++){
| ~^~~~~~~~~~~~
fish.cpp:55:27: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | while(p1+1<v[i-1].size() && v[i-1][p1+1]<=v[i][j])p1++;
| ~~~~^~~~~~~~~~~~~~
fish.cpp:56:27: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | while(p2+1<v[i-2].size() && v[i-1][p2+1]<=v[i][j])p2++;
| ~~~~^~~~~~~~~~~~~~
fish.cpp:59:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | if(p2<v[i-2].size()-1)dp[0]=max(dp[0],t3[p2+1]);
| ~~^~~~~~~~~~~~~~~~
fish.cpp:61:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | if(p1<v[i-1].size()-1)dp[1]=max(dp[1],t4[p2+1]-w[i][j]);
| ~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
75 ms |
30000 KB |
1st lines differ - on the 1st token, expected: '40313272768926', found: '40313272768992' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
120 ms |
51100 KB |
1st lines differ - on the 1st token, expected: '40604614618209', found: '65512925105028' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
16732 KB |
Output is correct |
2 |
Correct |
22 ms |
16740 KB |
Output is correct |
3 |
Incorrect |
55 ms |
21328 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '26724915989240' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
596 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
1 ms |
348 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '248544177493' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
596 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
1 ms |
348 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '248544177493' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
596 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
1 ms |
348 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '248544177493' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
16732 KB |
Output is correct |
2 |
Correct |
22 ms |
16740 KB |
Output is correct |
3 |
Incorrect |
55 ms |
21328 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '26724915989240' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
75 ms |
30000 KB |
1st lines differ - on the 1st token, expected: '40313272768926', found: '40313272768992' |
2 |
Halted |
0 ms |
0 KB |
- |