結果
| 問題 | No.3849 遠足のおやつ |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-12-04 21:58:18 |
| 言語 | C++23(gcc16) (gcc 16.2.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 619 ms / 2,000 ms |
| + 652µs | |
| コード長 | 1,851 bytes |
| 記録 | |
| コンパイル時間 | 3,027 ms |
| コンパイル使用メモリ | 362,780 KB |
| 実行使用メモリ | 785,280 KB |
| 最終ジャッジ日時 | 2026-12-04 21:58:29 |
| 合計ジャッジ時間 | 10,848 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 |
ソースコード
#include <algorithm>
#include <bits/stdc++.h>
#include <csetjmp>
using namespace std;
using ll = long long;
using ld = long double;
using pll = array<ll, 2>;
using vl = vector<ll>;
template <class T> using vec = vector<T>;
template <class T> using vv = vec<vec<T>>;
template <class T> using vvv = vv<vec<T>>;
template <class T> using minpq = priority_queue<T, vector<T>, greater<T>>;
#define all(a) (a).begin(), (a).end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define reps(i, l, r) for (ll i = (l); i < (r); ++i)
#define rrep(i, l, r) for (ll i = (r) - 1; i >= (l); --i)
#define sz(x) (ll)(x).size()
template <typename T> bool chmax(T &a, const T &b) {
return a < b ? a = b, true : false;
}
template <typename T> bool chmin(T &a, const T &b) {
return a > b ? a = b, true : false;
}
const ll INF = 1LL << 60;
using ull = unsigned long long;
using ulll = __uint128_t;
void solve() {
// s
// -> (s-d)*2=2s-2d = s + (s - 2d)
// -> (s-2d) * 3 = 3s - 6d = 2s-2d + (s - 4d)
// -> (s-3d) * 4 = 4s - 12d = 3s-6d + (s-6d)
ll n, b;
cin >> n >> b;
vec<pll> items; // cost, value
rep(i, n) {
ll p, c, s, d;
cin >> p >> c >> s >> d;
rrep(i, 0, c) {
items.push_back({p, s - d * 2 * i});
}
}
vv<ll> dp(items.size() + 1, vl(b+1, -INF));
dp[0][0] = 0;
rep(i, (ll)items.size()) {
auto [cost, value] = items[i];
// cout << cost << " " << value << endl;
rep(j, b+1) {
chmax(dp[i+1][j], dp[i][j]);
// cout << dp[i][j] << " \n"[j == b];
if(dp[i][j] == -INF) continue;
if(j + cost > b) continue;
chmax(dp[i+1][j + cost], dp[i][j] + value);
}
}
cout << *max_element(all(dp.back())) << endl;
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(20);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}