#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
typedef long long ll;
ll i, j, k, t, x, y, w, ans;
vector<ll> v[100005];
map<pair<ll, ll>, ll> m, p, dp;
set<ll> s;
set<ll> :: iterator it, it1;
ll max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W)
{
for(i = 0; i < M; i++)
{
v[X[i] + 1].pb(Y[i]);
m[{X[i], Y[i]}] = W[i];
}
for(i = 0; i < N; i++)
{
v[i].pb(0), v[i].pb(N);
sort(v[i].begin(), v[i].end());
}
for(i = 0; i < N; i++)
{
if(i)
for(j = 1; j < v[i - 1].size(); j++)
if(v[i - 1][j]) s.insert(v[i - 1][j] - 1);
for(j = 0; j < v[i].size() - 1; j++)
s.insert(v[i][j]);
if(i != N - 1)
for(j = 0; j < v[i + 1].size() - 1; j++)
s.insert(v[i + 1][j]);
s.insert(N - 1);
for(it = s.begin(); it != s.end(); it++)
{
p[{i, *it}] = 0;
if(m[{i,*it}]) p[{i, *it}] = m[{i, *it}];
if(it != s.begin())
{
it1 = it;
it1--;
p[{i, *it}] += p[{i, *it1}];
}
}
s.clear();
}
for(i = 1; i < N; i++)
{
k = 0; t = 0;
for(j = 0; j < v[i].size() - 1; j++)
{
if(j && v[i][j] == v[i][j - 1]) continue;
if(!j)
{
for(k = 0; k < v[i - 1].size() - 1; k++)
dp[{i, j}] = max(dp[{i, j}], dp[{i - 1, k}] + p[{i, v[i - 1][k + 1] - 1}]);
}
else
{
while(v[i - 1][k] < v[i][j])
{
if(!v[i - 1][k])
{
if(i == 1) { dp[{i, j}] = max(dp[{i, j}], p[{0, v[i][j]}]); continue; }
while(v[i - 2][t] < v[i][j])
{
dp[{i, j}] = max(dp[{i, j}], dp[{i - 2, t}] + p[{i - 1, v[i][j]}]);
t++;
}
}
else
dp[{i, j}] = max(dp[{i, j}], dp[{i - 1, k}] + p[{i - 1, v[i][j]}] - p[{i - 1, v[i - 1][k]}]);
k++;
}
dp[{i, j}] = max(dp[{i, j}], dp[{i, j - 1}] + p[{i, v[i][j]}] - p[{i, v[i][j - 1]}]);
}
}
}
for(i = 0; i < v[N - 1].size() - 1; i++)
ans = max(ans, dp[{N - 1, i}]);
return ans;
}
/*int main()
{
std::ios::sync_with_stdio(0);
cin.tie(0);
cin >> N >> M;
for(i = 0; i < M; i++)
{
cin >> x >> y >> w;
X.pb(x), Y.pb(y), W.pb(w);
}
cout << max_weights(N, M, X, Y, W) << "\n";
}*/
Compilation message
fish.cpp: In function 'll max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:30: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]
30 | for(j = 1; j < v[i - 1].size(); j++)
| ~~^~~~~~~~~~~~~~~~~
fish.cpp:32: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]
32 | for(j = 0; j < v[i].size() - 1; j++)
| ~~^~~~~~~~~~~~~~~~~
fish.cpp:35: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]
35 | for(j = 0; j < v[i + 1].size() - 1; j++)
| ~~^~~~~~~~~~~~~~~~~~~~~
fish.cpp:54: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]
54 | for(j = 0; j < v[i].size() - 1; j++)
| ~~^~~~~~~~~~~~~~~~~
fish.cpp:59:30: 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 | for(k = 0; k < v[i - 1].size() - 1; k++)
| ~~^~~~~~~~~~~~~~~~~~~~~
fish.cpp:83:18: 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]
83 | for(i = 0; i < v[N - 1].size() - 1; i++)
| ~~^~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
616 ms |
72900 KB |
1st lines differ - on the 1st token, expected: '40313272768926', found: '0' |
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: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
219 ms |
37072 KB |
1st lines differ - on the 1st token, expected: '10082010', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2648 KB |
1st lines differ - on the 1st token, expected: '3', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2648 KB |
1st lines differ - on the 1st token, expected: '3', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2648 KB |
1st lines differ - on the 1st token, expected: '3', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
219 ms |
37072 KB |
1st lines differ - on the 1st token, expected: '10082010', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
616 ms |
72900 KB |
1st lines differ - on the 1st token, expected: '40313272768926', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |