結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー FF256grhyFF256grhy
提出日時 2019-12-14 00:34:29
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 422 ms / 2,000 ms
コード長 2,562 bytes
コンパイル時間 1,916 ms
コンパイル使用メモリ 178,340 KB
実行使用メモリ 394,664 KB
最終ジャッジ日時 2023-09-10 08:06:41
合計ジャッジ時間 15,000 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 11 ms
12,436 KB
testcase_10 AC 8 ms
8,296 KB
testcase_11 AC 8 ms
8,584 KB
testcase_12 AC 86 ms
80,264 KB
testcase_13 AC 302 ms
276,204 KB
testcase_14 AC 50 ms
47,504 KB
testcase_15 AC 51 ms
50,748 KB
testcase_16 AC 77 ms
74,580 KB
testcase_17 AC 94 ms
91,512 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 6 ms
8,244 KB
testcase_22 AC 3 ms
5,096 KB
testcase_23 AC 5 ms
6,232 KB
testcase_24 AC 410 ms
394,512 KB
testcase_25 AC 420 ms
394,572 KB
testcase_26 AC 409 ms
394,480 KB
testcase_27 AC 407 ms
394,532 KB
testcase_28 AC 396 ms
394,616 KB
testcase_29 AC 396 ms
394,588 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 4 ms
5,672 KB
testcase_33 AC 5 ms
6,852 KB
testcase_34 AC 9 ms
10,808 KB
testcase_35 AC 403 ms
394,664 KB
testcase_36 AC 406 ms
394,560 KB
testcase_37 AC 415 ms
394,560 KB
testcase_38 AC 420 ms
394,532 KB
testcase_39 AC 422 ms
394,548 KB
testcase_40 AC 399 ms
394,620 KB
testcase_41 AC 405 ms
394,664 KB
testcase_42 AC 408 ms
394,524 KB
testcase_43 AC 407 ms
394,632 KB
testcase_44 AC 408 ms
394,576 KB
testcase_45 AC 410 ms
394,664 KB
testcase_46 AC 395 ms
394,624 KB
testcase_47 AC 397 ms
394,472 KB
testcase_48 AC 396 ms
394,664 KB
testcase_49 AC 395 ms
394,496 KB
testcase_50 AC 394 ms
394,480 KB
testcase_51 AC 396 ms
394,500 KB
testcase_52 AC 286 ms
317,920 KB
testcase_53 AC 349 ms
394,508 KB
testcase_54 AC 323 ms
394,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
auto fl = [](auto a, auto b) { assert(b != 0); return a / b - (a % b != 0 && ((a >= 0) != (b >= 0)) ? 1 : 0); };
auto ce = [](auto a, auto b) { assert(b != 0); return a / b + (a % b != 0 && ((a >= 0) == (b >= 0)) ? 1 : 0); };
auto mo = [](auto a, auto b) { assert(b != 0); a %= b; if(a < 0) { a += abs(b); } return a; };
LL gcd(LL a, LL b) { return (b == 0 ? a : gcd(b, a % b)); }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)

// ---- ----

#define T0(T) T
#define T1(T) vector<T0(T)>
#define T2(T) vector<T1(T)>
#define T3(T) vector<T2(T)>
#define V0(v, T,    ...) v
#define V1(v, T, n, ...) T1(T)(n, V0(v, T, __VA_ARGS__))
#define V2(v, T, n, ...) T2(T)(n, V1(v, T, __VA_ARGS__))
#define V3(v, T, n, ...) T3(T)(n, V2(v, T, __VA_ARGS__))

int main() {
	int n, k;
	cin >> n >> k;
	vector<pair<int, int>> v(n);
	inc(i, n) { cin >> v[i].FI >> v[i].SE; }
	
	sort(RALL(v));
	
	int INF = 1e9;
	auto dp = V3(-INF, int, n + 1, 2, 2 * k + 1);
	dp[0][0][0] = 0;
	inc(i, n) {
	inc(f, 2) {
	incII(p, 0, k) {
		if(dp[i][f][p] < 0) { continue; }
		setmax(dp[i + 1][f][p], dp[i][f][p]);
		setmax(dp[i + 1][f ^ 1][p + (f ^ 1) * v[i].FI], dp[i][f][p] + v[i].SE);
	}
	}
	}
	
	int ans = 0;
	incII(p, 0, k) { setmax(ans, dp[n][0][p]); }
	incII(p, 0, k) { setmax(ans, dp[n][1][p]); }
	
	cout << ans << endl;
	
	return 0;
}
0