#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll n, m, x, y, k;
ll max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> k) {
vector<ll> v(n);
for (int i = 0; i < m; i++) {
v[x[i]] += k[i];
}
vector<ll> dp1(n + 1);
vector<ll> dp2(n + 1);
for (int i = 1; i <= n; i++) {
if (i != n) {
dp2[i] = v[i - 1];
if (i >= 2) {
dp2[i] = max(dp2[i], dp2[i - 2] + v[i - 1]);
dp2[i] = max(dp2[i], dp1[i - 2] + v[i - 1]);
}
if (i >= 3) {
dp2[i] = max(dp2[i], dp1[i - 3] + v[i - 1]);
dp2[i] = max(dp2[i], dp2[i - 3] + v[i - 1]);
}
dp2[i] = max(dp2[i], dp1[i - 1] + v[i - 1]);
}
if (i != 1) {
dp1[i] = v[i - 1];
if (i >= 3) {
dp1[i] = max(dp1[i], dp1[i - 3] + v[i - 1]);
dp1[i] = max(dp1[i], dp2[i - 3] + v[i - 1]);
}
dp1[i] = max(dp1[i], dp2[i - 2] + v[i - 1]);
dp1[i] = max(dp1[i], dp1[i - 2] + v[i - 1]);
}
}
return max(*max_element(dp1.begin(), dp1.end()), *max_element(dp2.begin(), dp2.end()));
}
//void solve() {
// cin >> n >> m;
// vector<int> x(m);
// vector<int> y(m);
// vector<int> k(m);
// for (int i = 0; i < m; i++) {
// cin >> x[i] >> y[i] >> k[i];
// }
// cout << max_weights(n, m, x, y, k) << '\n';
//}
//
//int main() {
// ios_base::sync_with_stdio(0);
// cin.tie(0);
// cout.tie(0);
// solve();
//}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
4308 KB |
Output is correct |
2 |
Correct |
32 ms |
4928 KB |
Output is correct |
3 |
Correct |
3 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
89 ms |
9620 KB |
Output is correct |
6 |
Correct |
96 ms |
9568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
15 ms |
3636 KB |
Output is correct |
4 |
Correct |
12 ms |
3428 KB |
Output is correct |
5 |
Correct |
28 ms |
4944 KB |
Output is correct |
6 |
Correct |
22 ms |
4948 KB |
Output is correct |
7 |
Correct |
34 ms |
4940 KB |
Output is correct |
8 |
Correct |
27 ms |
4936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
15 ms |
3636 KB |
Output is correct |
4 |
Correct |
12 ms |
3428 KB |
Output is correct |
5 |
Correct |
28 ms |
4944 KB |
Output is correct |
6 |
Correct |
22 ms |
4948 KB |
Output is correct |
7 |
Correct |
34 ms |
4940 KB |
Output is correct |
8 |
Correct |
27 ms |
4936 KB |
Output is correct |
9 |
Incorrect |
25 ms |
4948 KB |
1st lines differ - on the 1st token, expected: '99999', found: '66666' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
4308 KB |
Output is correct |
2 |
Correct |
32 ms |
4928 KB |
Output is correct |
3 |
Correct |
3 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
89 ms |
9620 KB |
Output is correct |
6 |
Correct |
96 ms |
9568 KB |
Output is correct |
7 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
8 |
Halted |
0 ms |
0 KB |
- |