結果
| 問題 |
No.951 【本日限定】1枚頼むともう1枚無料!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-07-24 02:49:37 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 180 ms / 2,000 ms |
| コード長 | 843 bytes |
| コンパイル時間 | 2,361 ms |
| コンパイル使用メモリ | 204,208 KB |
| 最終ジャッジ日時 | 2025-01-12 04:51:32 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 52 |
ソースコード
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
int n, k;
cin >> n >> k;
vector<pair<int, int>> a(n);
for (auto& p : a) cin >> p.first >> p.second;
vector<vector<int>> dp(2, vector<int>(k + 1, -(1 << 30)));
dp[0][0] = dp[1][0] = 0;
sort(a.begin(), a.end());
for (int i = 0; i < n; i++) {
vector<vector<int>> nxt(2, vector<int>(k + 1, -(1 << 30)));
auto p = a[i].first;
auto d = a[i].second;
for (int u = 0; u < 2; u++) {
for (int j = 0; j <= k; j++) {
int c = u == 0 ? p : 0;
if (j + c <= k) nxt[u ^ 1][j + c] = max(nxt[u ^ 1][j + c], dp[u][j] + d);
nxt[u][j] = max(nxt[u][j], dp[u][j]);
}
}
dp.swap(nxt);
}
cout << *max_element(dp[1].begin(), dp[1].end()) << endl;
return 0;
}