#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
#define ll long long
#define endl "\n"
#define INF 1000000000
#define LINF 10000000000000000LL
#define pb push_back
#define all(x) x.begin(), x.end()
#define len(s) (int)s.size()
#define test_case { int t; cin>>t; while(t--)solve(); }
#define single_case solve();
#define line cerr<<"----------"<<endl;
#define ios { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL); }
#define mod 1000000007LL
long long max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) {
vector<ll> val(n, 0);
vector<set<ll> > visine(n);
for (int i = 0; i < m; ++i) {
visine[x[i]].insert(i);
val[x[i]] += w[i];
}
ll sigurno = 0;
for (int i = 0; i < n; ++i) {
ll cnt = 0;
if (i - 1 >= 0) {
for (ll ind : visine[i]) {
if (y[ind] >= *visine[i - 1].begin())
break;
cnt += w[ind];
}
}
if (i + 1 < n) {
ll cnt1 = 0;
for (ll ind : visine[i]) {
if (y[ind] >= *visine[i + 1].begin())
break;
cnt1 += w[ind];
}
cnt = max(cnt, cnt1);
}
sigurno += cnt;
val[i] -= cnt;
}
vector<vector<ll> > dp(n, vector<ll>(3, 0));
for (int i = 0; i < n; ++i) {
if (i - 1 >= 0) {
dp[i][0] = max({dp[i - 1][2], dp[i - 1][1], dp[i - 1][0]});
if (i + 1 < n)
dp[i][2] = max(dp[i - 1][1], dp[i - 1][0]);
}
if (i - 2 >= 0) {
dp[i][1] = max(dp[i - 2][1] , dp[i - 2][2]);
}
if (i - 1 >= 0)
dp[i][1] += val[i];
if (i + 1 < n)
dp[i][2] += val[i];
}
return max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]});
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
17236 KB |
Output is correct |
2 |
Correct |
47 ms |
20184 KB |
Output is correct |
3 |
Correct |
8 ms |
11356 KB |
Output is correct |
4 |
Correct |
8 ms |
11396 KB |
Output is correct |
5 |
Correct |
126 ms |
38748 KB |
Output is correct |
6 |
Correct |
189 ms |
39140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 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 |
9 ms |
11356 KB |
Output is correct |
2 |
Correct |
7 ms |
11356 KB |
Output is correct |
3 |
Incorrect |
26 ms |
14940 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '509833355105' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 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 |
0 ms |
348 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 |
0 ms |
348 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 |
9 ms |
11356 KB |
Output is correct |
2 |
Correct |
7 ms |
11356 KB |
Output is correct |
3 |
Incorrect |
26 ms |
14940 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '509833355105' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
17236 KB |
Output is correct |
2 |
Correct |
47 ms |
20184 KB |
Output is correct |
3 |
Correct |
8 ms |
11356 KB |
Output is correct |
4 |
Correct |
8 ms |
11396 KB |
Output is correct |
5 |
Correct |
126 ms |
38748 KB |
Output is correct |
6 |
Correct |
189 ms |
39140 KB |
Output is correct |
7 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
8 |
Halted |
0 ms |
0 KB |
- |