結果
| 問題 |
No.951 【本日限定】1枚頼むともう1枚無料!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-03-11 19:26:16 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 398 ms / 2,000 ms |
| コード長 | 2,023 bytes |
| コンパイル時間 | 1,432 ms |
| コンパイル使用メモリ | 120,320 KB |
| 実行使用メモリ | 395,168 KB |
| 最終ジャッジ日時 | 2024-11-16 00:21:42 |
| 合計ジャッジ時間 | 13,500 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 52 |
ソースコード
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
//constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
struct Pizza {
ll p, d;
Pizza(ll _p, ll _d) :p(_p), d(_d) {}
bool operator<(const Pizza& pizza) {
if (p == pizza.p) return d > pizza.d;
return p > pizza.p;
}
};
ll dp[5010][5010][2];
int main()
{
/*
cin.tie(nullptr);
ios::sync_with_stdio(false);
*/
ll n, K; scanf("%lld %lld", &n, &K);
for (int i = 0; i <= n; i++) for (int j = 0; j <= K; j++) for (int k = 0; k < 2; k++) dp[i][j][k] = -1;
vector<Pizza> v; v.reserve(n);
for (int i = 0; i < n; i++) {
ll p, d; scanf("%lld %lld", &p, &d);
v.emplace_back(p, d);
}
sort(v.begin(), v.end());
dp[0][0][0] = 0;
for (int i = 0; i < v.size(); i++) {
for (int j = 0; j <= K; j++) {
if (dp[i][j][0] != -1 && j + v[i].p <= K) chmax(dp[i + 1][j + v[i].p][1], dp[i][j][0] + v[i].d);
chmax(dp[i + 1][j][0], dp[i][j][0]);
chmax(dp[i + 1][j][1], dp[i][j][1]);
if (dp[i][j][1] != -1) chmax(dp[i + 1][j][0], dp[i][j][1] + v[i].d);
}
}
ll res = 0;
for (ll i = 0; i <= K; i++) chmax(res, max(dp[n][i][0], dp[n][i][1]));
cout << res << endl;
return 0;
/*
おまじないを使ったらscanfとprintf関連注意!!!!!!!!!!!!
*/
}