結果
| 問題 |
No.974 最後の日までに
|
| コンテスト | |
| ユーザー |
drken1215
|
| 提出日時 | 2020-01-19 09:55:22 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,773 bytes |
| コンパイル時間 | 867 ms |
| コンパイル使用メモリ | 86,992 KB |
| 実行使用メモリ | 23,296 KB |
| 最終ジャッジ日時 | 2024-07-02 21:34:23 |
| 合計ジャッジ時間 | 2,722 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 WA * 37 |
ソースコード
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
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; }
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
using pll = pair<long long, long long>;
const long long INF = 1LL<<60;
int N;
vector<long long> a, b, c;
// 後半の各所持金差額に対する獲得好感度の差分ん最大値を求める
void rec(int n, int finish, map<long long, long long> &ma, long long syoji = 0, long long love = 0) {
if (n == finish) {
chmax(ma[-syoji], love);
return;
}
// アルバイト
rec(n + 1, finish, ma, syoji + a[n], love);
// 学校からのデート
if (n + 2 <= finish) rec(n + 2, finish, ma, syoji - c[n+1], love + b[n+1]);
}
long long solve(int mid) {
map<long long, long long> former, latter;
rec(0, mid, former);
rec(mid, N, latter);
long long cur = -INF;
map<long long, long long> maxlatter;
maxlatter[-INF] = -INF;
for (auto it : latter) maxlatter[it.first] = max(cur, it.second);
//COUT(former); COUT(latter); COUT(maxlatter);
long long res = 0;
for (auto it : former) {
long long need = -(it.first);
auto it2 = maxlatter.upper_bound(need);
--it2;
chmax(res, it.second + it2->second);
//cout << pll(it.first, it.second) << ": " << pll(it2->first, it2->second) << endl;
}
return res;
}
long long naive() {
map<long long, long long> ma;
rec(0, N, ma);
long long res = 0;
for (auto it : ma) if (it.first <= 0) chmax(res, it.second);
return res;
}
int main() {
while (cin >> N) {
a.resize(N), b.resize(N), c.resize(N);
for (int i = 0; i < N; ++i) cin >> a[i] >> b[i] >> c[i];
if (N <= 30) cout << naive() << endl;
else cout << -1 << endl;
//cout << max(solve(max(0, N/2-1)), max(solve(N/2), solve(N/2+1))) << endl;
}
}
drken1215