結果
問題 | No.1826 Fruits Collecting |
ユーザー |
![]() |
提出日時 | 2022-01-28 23:01:33 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 264 ms / 2,000 ms |
コード長 | 2,523 bytes |
コンパイル時間 | 1,641 ms |
コンパイル使用メモリ | 133,052 KB |
最終ジャッジ日時 | 2025-01-27 17:17:12 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 43 |
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <deque> #include <set> #include <map> #include <tuple> #include <cmath> #include <numeric> #include <functional> #include <cassert> #include <atcoder/segtree> #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; 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; } using namespace std; typedef long long ll; template<typename T> vector<vector<T>> vec2d(int n, int m, T v){ return vector<vector<T>>(n, vector<T>(m, v)); } template<typename T> vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){ return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v))); } template<typename T> void print_vector(vector<T> v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } template<typename T> class Compress{ public: vector<T> data; int offset; Compress(vector<T> data_, int offset=0): offset(offset){ set<T> st; for(T x: data_) st.insert(x); for(T x: st) data.push_back(x); }; int operator[](T x) { auto p = lower_bound(data.begin(), data.end(), x); assert(x == *p); return offset+(p-data.begin()); } T inv(int x){ return data[x-offset]; } int size(){ return data.size(); } }; using T = tuple<ll, ll, ll>; const ll inf = 1e18; ll e(){ return -inf; } ll op(ll x, ll y){ return max(x, y); } using Seg = atcoder::segtree<ll, op, e>; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n; cin >> n; vector<T> vt(n); vector<ll> vv = {-inf, 0, inf}; for(int i = 0; i < n; i++){ ll t, x, v; cin >> t >> x >> v; vt[i] = T(x+t, -(x-t), v); vv.push_back(x-t); } sort(vt.begin(), vt.end()); auto cp = Compress<ll>(vv); int m = cp.size(); Seg dp(m); dp.set(cp[0], 0); for(auto [X, _Y, v]: vt){ if(X < 0) continue; ll Y = -_Y; int l = cp[Y]; ll mx = dp.prod(l, m); dp.set(l, mx+v); } cout << dp.all_prod() << endl; }