Submission #25578

#TimeUsernameProblemLanguageResultExecution timeMemory
25578khsoo01스트랩 (JOI14_straps)C++11
100 / 100
29 ms33456 KiB
#include<bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef long long ll;
const ll inf = 1e18;

ll n, dt[2005][2005];
pair<ll,ll> a[2005];

int main()
{
	scanf("%lld",&n);
	for(ll i=1;i<=n;i++) {
		scanf("%lld%lld",&a[i].X,&a[i].Y);
		a[i].X *= -1;
	}
	sort(a+1, a+1+n);
	for(ll i=1;i<=n;i++) a[i].X *= -1;
	for(ll i=0;i<=n;i++) {
		for(ll j=0;j<=n;j++) dt[i][j] = -inf;
	}
	dt[0][1] = 0;
	for(ll i=1;i<=n;i++) {
		dt[i][0] = dt[i-1][0];
		for(ll j=1;j<=n;j++) {
			dt[i][j] = max(dt[i][j], dt[i-1][j]);
			if(j + a[i].X - 1 >= 0) {
				ll X = min(n, j+a[i].X-1);
				dt[i][X] = max(dt[i][X], dt[i-1][j] + a[i].Y);
			}
		}
	}
	ll ans = 0;
	for(ll i=0;i<=n;i++) ans = max(ans, dt[n][i]);
	printf("%lld\n",ans);
}

Compilation message (stderr)

straps.cpp: In function 'int main()':
straps.cpp:13:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld",&n);
                  ^
straps.cpp:15:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld",&a[i].X,&a[i].Y);
                                    ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...