Submission #818975

# Submission time Handle Problem Language Result Execution time Memory
818975 2023-08-10T07:30:06 Z Alan 스트랩 (JOI14_straps) C++17
55 / 100
7 ms 444 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll dp[2005];
const ll inf = 1e18;

int main () {
	int n;
	cin >> n;
	vector<ll> cand {};
	for (int i = 2; i <= 2000; i++) dp[i] = -inf;
	ll base = 0;
	while (n--) {
		ll a, b;
		cin >> a >> b;
		if (a && b >= 0) {
			for (int i = 2000; i >= a; i--) dp[i] = dp[i-a+1];
			for (int i = 1; i < a; i++) dp[i] = 0;
			base += b;
		} else if (b >= 0) cand.push_back(b);
		else if (a > 1) for (int i = 2000; i >= a; i--) dp[i] = max(dp[i], dp[i-a+1] + b);
	}
	sort(cand.rbegin(), cand.rend());
	int sz = cand.size();
	for (int i = 1; i < sz; i++) cand[i] += cand[i-1];
	ll ans = 0;
	if (!cand.empty()) for (int i = 0; i < 2000; i++) ans = max(ans, dp[i+1] + cand[min(i, sz-1)]);
	cout << ans+base << '\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 304 KB Output is correct
3 Correct 0 ms 304 KB Output is correct
4 Correct 0 ms 260 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 300 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 256 KB Output is correct
23 Correct 0 ms 304 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 260 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 308 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 2 ms 316 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 1 ms 312 KB Output is correct
20 Correct 2 ms 316 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 316 KB Output is correct
25 Correct 2 ms 364 KB Output is correct
26 Correct 2 ms 320 KB Output is correct
27 Correct 3 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 3 ms 340 KB Output is correct
30 Correct 3 ms 340 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 0 ms 304 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 312 KB Output is correct
17 Correct 2 ms 312 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 2 ms 316 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 312 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 2 ms 316 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 7 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 2 ms 316 KB Output is correct
9 Correct 1 ms 444 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Incorrect 2 ms 340 KB Output isn't correct
12 Halted 0 ms 0 KB -