結果
| 問題 |
No.951 【本日限定】1枚頼むともう1枚無料!
|
| コンテスト | |
| ユーザー |
tarattata1
|
| 提出日時 | 2019-12-14 00:38:03 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 156 ms / 2,000 ms |
| コード長 | 1,663 bytes |
| コンパイル時間 | 775 ms |
| コンパイル使用メモリ | 78,032 KB |
| 実行使用メモリ | 198,792 KB |
| 最終ジャッジ日時 | 2024-06-27 23:42:15 |
| 合計ジャッジ時間 | 6,204 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 52 |
コンパイルメッセージ
main.cpp: In function ‘int main(int, char**)’:
main.cpp:31:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
31 | scanf("%d%d", &n, &K);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:36:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
36 | scanf("%d%d", &p, &d);
| ~~~~~^~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996)
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;
int dp[5005][5005][2];
int main(int argc, char* argv[])
{
int n,K;
scanf("%d%d", &n, &K);
vector<pair<int,int> > z(n);
int i,j,k;
for(i=0; i<n; i++) {
int p,d;
scanf("%d%d", &p, &d);
z[i]=make_pair(p,d);
}
sort(z.rbegin(),z.rend());
for(i=0; i<n; i++) {
for(j=0; j<=K; j++) {
for(k=0; k<2; k++) {
dp[i][j][k]=-INF;
}
}
}
dp[0][K][0]=0;
for(i=0; i<n; i++) {
for(j=0; j<=K; j++) {
for(k=0; k<2; k++) {
dp[i+1][j][k]=dp[i][j][k];
}
}
for(j=0; j<=K; j++) {
for(k=0; k<2; k++) {
if(dp[i][j][k]>=0) {
int j2=(k==0? j-z[i].first: j);
if(j2>=0 && j2<=K) {
dp[i+1][j2][1-k]=MAX(dp[i+1][j2][1-k],dp[i][j][k]+z[i].second);
}
}
}
}
}
int ans=0;
for(j=0; j<=K; j++) {
for(k=0; k<2; k++) {
ans=MAX(ans,dp[n][j][k]);
}
}
printf("%d\n", ans);
return 0;
}
tarattata1