#include <bits/stdc++.h>
#include "fish.h"
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<pii, ll> tri;
const int MAXN = 100010;
const ll INF = 1e18;
vector<pii> HW[MAXN];
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) {
vector<tri> P;
for(int i=0 ; i<M ; i++){
P.emplace_back(pii(X[i], Y[i]), W[i]);
}
sort(P.begin(), P.end());
for(int i=0 ; i<M ; i++){
HW[P[i].first.first].emplace_back(P[i].first.second, P[i].second);
}
vector<ll> U(HW[0].size(), 0), D(HW[0].size(), 0);
ll T = 0, S = 0;
for(int j=0 ; j<HW[0].size() ; j++){
S += HW[0][j].second;
D[j] = S;
}
for(int i=1 ; i<N ; i++){
vector<ll> new_U(HW[i].size(), 0), new_D(HW[i].size(), 0);
ll S = 0, ma = -INF;
for(int j=HW[i].size()-1 ; j>=0 ; j--){
S += HW[i][j].second;
new_U[j] = T + S;
}
S = 0;
for(int j=HW[i].size()-1 ; j>=0 ; j--){
auto [x, w] = HW[i][j];
int idx = lower_bound(HW[i-1].begin(), HW[i-1].end(), pii(x+1, 0)) - HW[i-1].begin();
if(idx < U.size()){
ma = max(ma, U[idx] - S);
new_U[j] = max(new_U[j], ma + (S + w));
}
S += w;
}
S = 0, ma = -INF;
for(int j=0 ; j<HW[i].size() ; j++){
S += HW[i][j].second;
if(U.size())
new_D[j] = U[0] + S;
else
new_D[j] = S;
}
S = 0;
for(int j=0 ; j<HW[i].size() ; j++){
auto [x, w] = HW[i][j];
int idx = lower_bound(HW[i-1].begin(), HW[i-1].end(), pii(x-1, 0)) - HW[i-1].begin() - 1;
if(idx >= 0 && idx < U.size()){
ma = max(ma, D[idx] - S);
new_D[j] = max(new_D[j], ma + (S + w));
}
S += w;
}
if(U.size()){
T = max(T, U[0]);
T = max(T, D[D.size()-1]);
}
U = new_U;
D = new_D;
}
if(U.size()){
T = max(T, U[0]);
}
return T;
}
Compilation message
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:24:20: 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]
24 | for(int j=0 ; j<HW[0].size() ; j++){
| ~^~~~~~~~~~~~~
fish.cpp:40:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | if(idx < U.size()){
| ~~~~^~~~~~~~~~
fish.cpp:47:24: 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]
47 | for(int j=0 ; j<HW[i].size() ; j++){
| ~^~~~~~~~~~~~~
fish.cpp:55:24: 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]
55 | for(int j=0 ; j<HW[i].size() ; j++){
| ~^~~~~~~~~~~~~
fish.cpp:58:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | if(idx >= 0 && idx < U.size()){
| ~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
9660 KB |
Output is correct |
2 |
Correct |
53 ms |
10940 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
3 ms |
2644 KB |
Output is correct |
5 |
Correct |
134 ms |
25356 KB |
Output is correct |
6 |
Correct |
144 ms |
23648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2644 KB |
Output is correct |
2 |
Correct |
3 ms |
2644 KB |
Output is correct |
3 |
Correct |
30 ms |
6856 KB |
Output is correct |
4 |
Correct |
21 ms |
5396 KB |
Output is correct |
5 |
Correct |
50 ms |
10420 KB |
Output is correct |
6 |
Correct |
48 ms |
10476 KB |
Output is correct |
7 |
Correct |
48 ms |
10464 KB |
Output is correct |
8 |
Correct |
48 ms |
10384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2644 KB |
Output is correct |
2 |
Correct |
3 ms |
2644 KB |
Output is correct |
3 |
Correct |
30 ms |
6856 KB |
Output is correct |
4 |
Correct |
21 ms |
5396 KB |
Output is correct |
5 |
Correct |
50 ms |
10420 KB |
Output is correct |
6 |
Correct |
48 ms |
10476 KB |
Output is correct |
7 |
Correct |
48 ms |
10464 KB |
Output is correct |
8 |
Correct |
48 ms |
10384 KB |
Output is correct |
9 |
Incorrect |
50 ms |
10424 KB |
1st lines differ - on the 1st token, expected: '99999', found: '66666' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
9660 KB |
Output is correct |
2 |
Correct |
53 ms |
10940 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
3 ms |
2644 KB |
Output is correct |
5 |
Correct |
134 ms |
25356 KB |
Output is correct |
6 |
Correct |
144 ms |
23648 KB |
Output is correct |
7 |
Incorrect |
2 ms |
2644 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
8 |
Halted |
0 ms |
0 KB |
- |