#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
const int N = 1e5 + 5;
const int M = 3e5 + 5;
const long long LL = 1e18;
ll ans;
map<ll, ll> dp[N][2];
vector<pair<ll, ll>> pref[N];
vector<int> wys[N];
bool zero[N];
ll max_weights(int n, int m, vector<int>X, vector<int>Y, vector<int>Z){
cin>>n>>m;
for(int i=0;i<m;i++){
pref[X[i]].pb({Y[i], Z[i]});
if(Y[i]==0) zero[X[i]]=true;
wys[X[i]].pb(Y[i]);
}
for(int i = 0; i < n; ++i) {
wys[i].pb(n);
if(!zero[i])wys[i].pb(0);
sort(wys[i].begin(), wys[i].end());
}
for(int i=0;i<n;i++){
sort(pref[i].begin(), pref[i].end());
ll suma=0;
for(int j=0;j<pref[i].size();j++) {
suma+=pref[i][j].second;
pref[i][j].second = suma;
}
pref[i].insert(pref[i].begin(), make_pair(-1, 0));
}
for(int i=1;i<n;i++){
vector<pair<ll, ll>> spr1, spr2;
for(ll pom : wys[i-1]){
dp[i][0][0]=max({dp[i][0][0], dp[i-1][0][pom], dp[i-1][1][pom]});
dp[i][1][0]=max({dp[i][1][0], dp[i-1][0][pom], dp[i-1][1][pom]});
ll res=0;
if(!spr1.empty()) res=spr1.back().second;
auto it = upper_bound(pref[i-1].begin(), pref[i-1].end(), make_pair(pom-1, LL));
it--;
res=max(res, dp[i-1][0][pom]-it->second);
spr1.pb({pom, res});
}
reverse(wys[i-1].begin(), wys[i-1].end());
for(ll pom : wys[i-1]){
ll res=0;
if(!spr2.empty()) res=spr2.back().second;
auto it = upper_bound(pref[i].begin(), pref[i].end(), make_pair(pom-1, LL));
it--;
res = max(res, dp[i - 1][0][pom] + it->second);
res = max(res, dp[i - 1][1][pom] + it->second);
spr2.pb({pom, res});
}
reverse(spr2.begin(), spr2.end());
for(ll pom : wys[i]){
auto op1 = upper_bound(spr1.begin(), spr1.end(), make_pair(pom, LL));
op1--;
auto op2 = lower_bound(spr2.begin(), spr2.end(), make_pair(pom, -LL));
auto tmp1 = lower_bound(pref[i-1].begin(), pref[i-1].end(), make_pair(pom, LL));
tmp1--;
dp[i][0][pom]=max(dp[i][0][pom], op1->second + tmp1->second);
auto tmp2 = lower_bound(pref[i].begin(), pref[i].end(), make_pair(pom, LL));
tmp2--;
dp[i][1][pom]=max(dp[i][1][pom], op2->second - tmp2->second);
}
}
for(int i=0;i<n;i++){
ans = max({ans, dp[n-1][0][i], dp[n-1][1][i]});
}
return ans;
}
Compilation message
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:28:16: 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]
28 | for(int j=0;j<pref[i].size();j++) {
| ~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
218 ms |
68660 KB |
Output is correct |
2 |
Correct |
280 ms |
76532 KB |
Output is correct |
3 |
Correct |
112 ms |
58192 KB |
Output is correct |
4 |
Correct |
118 ms |
58172 KB |
Output is correct |
5 |
Correct |
694 ms |
114840 KB |
Output is correct |
6 |
Correct |
423 ms |
117452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
14380 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
122 ms |
58144 KB |
Output is correct |
2 |
Incorrect |
122 ms |
58224 KB |
1st lines differ - on the 1st token, expected: '882019', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
14376 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
14376 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
14376 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
122 ms |
58144 KB |
Output is correct |
2 |
Incorrect |
122 ms |
58224 KB |
1st lines differ - on the 1st token, expected: '882019', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
218 ms |
68660 KB |
Output is correct |
2 |
Correct |
280 ms |
76532 KB |
Output is correct |
3 |
Correct |
112 ms |
58192 KB |
Output is correct |
4 |
Correct |
118 ms |
58172 KB |
Output is correct |
5 |
Correct |
694 ms |
114840 KB |
Output is correct |
6 |
Correct |
423 ms |
117452 KB |
Output is correct |
7 |
Incorrect |
8 ms |
14380 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
8 |
Halted |
0 ms |
0 KB |
- |