結果
問題 | No.777 再帰的ケーキ |
ユーザー |
![]() |
提出日時 | 2018-12-24 00:04:20 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 118 ms / 2,000 ms |
コード長 | 833 bytes |
コンパイル時間 | 553 ms |
コンパイル使用メモリ | 48,000 KB |
実行使用メモリ | 7,236 KB |
最終ジャッジ日時 | 2024-09-25 10:47:29 |
合計ジャッジ時間 | 4,183 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 33 |
ソースコード
#include <stdio.h>#include <algorithm>using namespace std;struct Cake{int a,b,c;bool operator <(const Cake &t)const{if (a != t.a) return a < t.a;return b > t.b;}}C[200200];int N,V;long long B[200200];void push(int x, long long u){while (x <= V){B[x] = max(B[x],u);x += x & (-x);}}long long pop(int x){long long r = 0;while (x){r = max(r,B[x]);x -= x & (-x);}return r;}int main(){scanf ("%d",&N);for (int i=0;i<N;i++) scanf ("%d %d %d",&C[i].a,&C[i].b,&C[i].c);sort(C,C+N,[](const Cake& a, const Cake& b){return a.b < b.b;});int l = -1;for (int i=0;i<N;i++){if (C[i].b != l){l = C[i].b;V++;}C[i].b = V;}sort(C,C+N);for (int i=0;i<N;i++){long long u = pop(C[i].b-1) + C[i].c;push(C[i].b,u);}printf("%lld\n",pop(V));return 0;}