답안 #899367

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
899367 2024-01-05T22:44:35 Z MongHwa 스트랩 (JOI14_straps) C++17
100 / 100
6 ms 604 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#define X first
#define Y second
#define INF 0x7f7f7f7f

int dp[2005];
vector<pair<int, int>> pos;
vector<int> zero;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;

	fill(dp, dp+n+1, -INF);

	for(int i = 0; i < n; i++)
	{
		int a, b;
		cin >> a >> b;

		if(a > 0)
			pos.push_back({a, b});
		else
			zero.push_back(b);
	}

	dp[1] = 0;
	for(int i = 0; i < (int)pos.size(); i++)
	{
		for(int j = n; j >= max(1, n-pos[i].X+1); j--)
			dp[n] = max(dp[n], dp[j] + pos[i].Y);
		for(int j = n-1; j >= max(1, pos[i].X-1); j--)
			dp[j] = max(dp[j], dp[j-pos[i].X+1] + pos[i].Y);
	}

	sort(zero.begin(), zero.end(), greater<>());

	int ans = 0;
	int sum = 0;
	for(int i = 1; i <= n; i++)
	{
		if(i <= (int)zero.size() && zero[i-1] >= 0)
			sum += zero[i-1];
		ans = max(ans, dp[i] + sum);
	}

	if(!zero.empty())
		ans = max(ans, zero[0]);
	cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 3 ms 604 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 480 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 6 ms 348 KB Output is correct
30 Correct 5 ms 348 KB Output is correct
31 Correct 5 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 0 ms 352 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 356 KB Output is correct
6 Correct 0 ms 356 KB Output is correct
7 Correct 0 ms 356 KB Output is correct
8 Correct 1 ms 356 KB Output is correct
9 Correct 1 ms 548 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 3 ms 604 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 600 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 6 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 5 ms 348 KB Output is correct
20 Correct 6 ms 496 KB Output is correct
21 Correct 6 ms 348 KB Output is correct
22 Correct 5 ms 348 KB Output is correct
23 Correct 6 ms 348 KB Output is correct
24 Correct 5 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct