結果
問題 | No.951 【本日限定】1枚頼むともう1枚無料! |
ユーザー | 👑 hos.lyric |
提出日時 | 2019-12-14 00:07:45 |
言語 | D (dmd 2.106.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,259 bytes |
コンパイル時間 | 739 ms |
コンパイル使用メモリ | 116,908 KB |
実行使用メモリ | 205,556 KB |
最終ジャッジ日時 | 2023-09-04 03:55:42 |
合計ジャッジ時間 | 11,454 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 2 ms
4,380 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | AC | 2 ms
4,376 KB |
testcase_06 | AC | 1 ms
4,376 KB |
testcase_07 | AC | 1 ms
4,376 KB |
testcase_08 | AC | 1 ms
4,380 KB |
testcase_09 | AC | 11 ms
9,168 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 67 ms
47,740 KB |
testcase_13 | AC | 242 ms
152,096 KB |
testcase_14 | AC | 38 ms
30,128 KB |
testcase_15 | WA | - |
testcase_16 | AC | 69 ms
49,880 KB |
testcase_17 | AC | 93 ms
76,772 KB |
testcase_18 | AC | 1 ms
4,380 KB |
testcase_19 | AC | 2 ms
4,384 KB |
testcase_20 | AC | 1 ms
4,380 KB |
testcase_21 | AC | 5 ms
5,868 KB |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | AC | 289 ms
204,124 KB |
testcase_25 | AC | 335 ms
204,032 KB |
testcase_26 | AC | 348 ms
204,108 KB |
testcase_27 | AC | 346 ms
204,124 KB |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | AC | 1 ms
4,380 KB |
testcase_31 | AC | 1 ms
4,376 KB |
testcase_32 | AC | 4 ms
5,076 KB |
testcase_33 | AC | 4 ms
5,096 KB |
testcase_34 | AC | 6 ms
6,660 KB |
testcase_35 | AC | 297 ms
204,188 KB |
testcase_36 | AC | 292 ms
204,128 KB |
testcase_37 | AC | 352 ms
204,052 KB |
testcase_38 | AC | 341 ms
204,064 KB |
testcase_39 | AC | 340 ms
203,936 KB |
testcase_40 | AC | 361 ms
204,028 KB |
testcase_41 | AC | 353 ms
203,800 KB |
testcase_42 | AC | 355 ms
204,060 KB |
testcase_43 | AC | 352 ms
203,972 KB |
testcase_44 | AC | 352 ms
203,932 KB |
testcase_45 | AC | 349 ms
204,024 KB |
testcase_46 | AC | 350 ms
204,028 KB |
testcase_47 | AC | 338 ms
203,948 KB |
testcase_48 | AC | 336 ms
203,948 KB |
testcase_49 | AC | 335 ms
204,140 KB |
testcase_50 | AC | 334 ms
204,128 KB |
testcase_51 | WA | - |
testcase_52 | AC | 184 ms
163,900 KB |
testcase_53 | AC | 213 ms
204,168 KB |
testcase_54 | AC | 164 ms
203,984 KB |
ソースコード
import std.conv, std.functional, std.range, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken.to!int; } long readLong() { return readToken.to!long; } real readReal() { return readToken.to!real; } bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } } bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } } int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; } int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); } int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); } void main() { try { for (; ; ) { const N = readInt(); const K = readInt(); auto A = new Tuple!(int, "p", int, "d")[N]; foreach (i; 0 .. N) { A[i].p = readInt(); A[i].d = readInt(); } A.sort!"a.p < b.p"; auto dp0 = new int[][](N + 1, K + 1); auto dp1 = new int[][](N + 1, K + 1); foreach (i; 0 .. N + 1) { dp0[i][] = -1; dp1[i][] = -1; } dp0[0][0] = 0; foreach (i; 0 .. N) { foreach (x; 0 .. K + 1) { if (dp0[i][x] >= 0) { chmax(dp0[i + 1][x], dp0[i][x]); chmax(dp1[i + 1][x], dp0[i][x] + A[i].d); } } foreach (x; 0 .. K + 1) { if (dp1[i][x] >= 0) { chmax(dp1[i + 1][x], dp1[i][x]); if (x + A[i].p <= K) { chmax(dp0[i + 1][x + A[i].p], dp1[i][x] + A[i].d); } } } } int ans = -1; foreach (x; 0 .. K + 1) { chmax(ans, dp0[N][x]); } writeln(ans); } } catch (EOFException e) { } }