結果
問題 | No.951 【本日限定】1枚頼むともう1枚無料! |
ユーザー | 👑 hos.lyric |
提出日時 | 2019-12-14 00:09:45 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 371 ms / 2,000 ms |
コード長 | 2,280 bytes |
コンパイル時間 | 830 ms |
コンパイル使用メモリ | 116,864 KB |
実行使用メモリ | 205,804 KB |
最終ジャッジ日時 | 2023-09-04 03:56:38 |
合計ジャッジ時間 | 12,146 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 2 ms
4,380 KB |
testcase_03 | AC | 2 ms
4,384 KB |
testcase_04 | AC | 1 ms
4,380 KB |
testcase_05 | AC | 1 ms
4,384 KB |
testcase_06 | AC | 2 ms
4,376 KB |
testcase_07 | AC | 1 ms
4,376 KB |
testcase_08 | AC | 1 ms
4,376 KB |
testcase_09 | AC | 11 ms
9,560 KB |
testcase_10 | AC | 6 ms
5,600 KB |
testcase_11 | AC | 7 ms
5,776 KB |
testcase_12 | AC | 70 ms
49,248 KB |
testcase_13 | AC | 254 ms
152,120 KB |
testcase_14 | AC | 40 ms
29,596 KB |
testcase_15 | AC | 48 ms
34,068 KB |
testcase_16 | AC | 71 ms
50,284 KB |
testcase_17 | AC | 95 ms
75,508 KB |
testcase_18 | AC | 1 ms
4,380 KB |
testcase_19 | AC | 1 ms
4,380 KB |
testcase_20 | AC | 1 ms
4,380 KB |
testcase_21 | AC | 5 ms
5,820 KB |
testcase_22 | AC | 3 ms
4,380 KB |
testcase_23 | AC | 4 ms
4,580 KB |
testcase_24 | AC | 305 ms
205,084 KB |
testcase_25 | AC | 350 ms
205,564 KB |
testcase_26 | AC | 363 ms
204,328 KB |
testcase_27 | AC | 364 ms
204,612 KB |
testcase_28 | AC | 345 ms
203,976 KB |
testcase_29 | AC | 349 ms
205,112 KB |
testcase_30 | AC | 1 ms
4,380 KB |
testcase_31 | AC | 2 ms
4,380 KB |
testcase_32 | AC | 3 ms
5,064 KB |
testcase_33 | AC | 5 ms
5,384 KB |
testcase_34 | AC | 6 ms
6,664 KB |
testcase_35 | AC | 303 ms
204,208 KB |
testcase_36 | AC | 302 ms
205,804 KB |
testcase_37 | AC | 358 ms
204,452 KB |
testcase_38 | AC | 359 ms
204,852 KB |
testcase_39 | AC | 352 ms
204,036 KB |
testcase_40 | AC | 371 ms
204,580 KB |
testcase_41 | AC | 363 ms
204,380 KB |
testcase_42 | AC | 368 ms
204,268 KB |
testcase_43 | AC | 362 ms
204,504 KB |
testcase_44 | AC | 369 ms
204,476 KB |
testcase_45 | AC | 366 ms
205,384 KB |
testcase_46 | AC | 355 ms
205,224 KB |
testcase_47 | AC | 350 ms
205,016 KB |
testcase_48 | AC | 347 ms
204,880 KB |
testcase_49 | AC | 345 ms
205,736 KB |
testcase_50 | AC | 351 ms
205,124 KB |
testcase_51 | AC | 353 ms
205,076 KB |
testcase_52 | AC | 191 ms
164,352 KB |
testcase_53 | AC | 222 ms
204,424 KB |
testcase_54 | AC | 167 ms
204,324 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; dp1[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) { } }