結果
問題 | No.777 再帰的ケーキ |
ユーザー |
|
提出日時 | 2018-12-24 10:17:09 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 317 ms / 2,000 ms |
コード長 | 995 bytes |
コンパイル時間 | 754 ms |
コンパイル使用メモリ | 71,832 KB |
実行使用メモリ | 7,936 KB |
最終ジャッジ日時 | 2024-09-25 10:57:40 |
合計ジャッジ時間 | 4,506 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 33 |
ソースコード
#include <iostream>#include <algorithm>#include <vector>using namespace std;struct P {int a, b, c;};bool operator<(P x, P y) {if (x.a != y.a) return x.a < y.a;return x.b > y.b;}long long bit[200001];void update(int k, long long v) {for (int i = k + 1; i <= 200000; i += i & -i) {bit[i] = max(bit[i], v);}}long long query(int k) {long long res = 0;for (int i = k; i > 0; i -= i & -i) {res = max(res, bit[i]);}return res;}int main() {int n;cin >> n;vector<P> a(n);vector<int> d(n);for (int i = 0; i < n; i++) {cin >> a[i].a >> a[i].b >> a[i].c;d[i] = a[i].b;}sort(a.begin(), a.end());sort(d.begin(), d.end());d.erase(unique(d.begin(), d.end()), d.end());for (int i = 0; i < n; i++) {a[i].b = lower_bound(d.begin(), d.end(), a[i].b) - d.begin();update(a[i].b, query(a[i].b) + a[i].c);}cout << query(200000) << endl;}