제출 #955265

#제출 시각아이디문제언어결과실행 시간메모리
955265yellowtoad스트랩 (JOI14_straps)C++17
100 / 100
14 ms32348 KiB
#include <iostream>
#include <algorithm>
#define f first
#define s second
using namespace std;

long long n, x, y, dp[2010][2010], maxx;
pair<long long,long long> a[2010];

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i].f >> a[i].s;
	sort(a+1,a+n+1,greater<pair<long long,long long>>());
	dp[0][0] = -1e18;
	for (int i = 2; i <= n; i++) dp[0][i] = -1e18;
	for (int i = 1; i <= n; i++) {
		x = a[i].f; y = a[i].s;
		for (int j = 0; j < n; j++) {
			dp[i][j] = dp[i-1][j];
			if (j-x+1 >= 0) dp[i][j] = max(dp[i][j],dp[i-1][j-x+1]+y);
		}
		dp[i][n] = dp[i-1][n];
		for (int j = n-x+1; j <= n; j++) dp[i][n] = max(dp[i][n],dp[i-1][j]+y);
	}
	for (int i = 0; i <= n; i++) maxx = max(maxx,dp[n][i]);
	cout << maxx << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...