結果
| 問題 |
No.951 【本日限定】1枚頼むともう1枚無料!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-12-17 03:15:32 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 216 ms / 2,000 ms |
| コード長 | 1,161 bytes |
| コンパイル時間 | 1,044 ms |
| コンパイル使用メモリ | 124,428 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-22 03:41:54 |
| 合計ジャッジ時間 | 8,271 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 52 |
ソースコード
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;
void main() {
auto s = readln.split.map!(to!int);
auto N = s[0];
auto M = s[1];
auto A = iota(N).map!(_ => readln.split.map!(to!int).array).array;
A.sort!"a[0] > b[0]";
auto dp = new int[][][](2, M+1, 2);
foreach (i; 0..2) foreach (j; 0..M+1) dp[i][j][1] = -(1 << 29);
int cur = 0;
int tar = 1;
foreach (i; 0..N) {
int p = A[i][0];
int d = A[i][1];
foreach (j; 0..M+1) {
dp[tar][j][0] = 0;
dp[tar][j][1] = -(1 << 29);
}
foreach (j; 0..M+1) {
dp[tar][j][0] = max(dp[tar][j][0], dp[cur][j][0]);
dp[tar][j][1] = max(dp[tar][j][1], dp[cur][j][1]);
if (p + j <= M) dp[tar][j+p][1] = max(dp[tar][j+p][1], dp[cur][j][0] + d);
dp[tar][j][0] = max(dp[tar][j][0], dp[cur][j][1] + d);
}
swap(cur, tar);
}
int ans = 0;
foreach (j; 0..M+1) foreach (k; 0..2) ans = max(ans, dp[cur][j][k]);
ans.writeln;
}