Submission #1135011

#TimeUsernameProblemLanguageResultExecution timeMemory
1135011ByeWorldSalesman (IOI09_salesman)C++20
40 / 100
3096 ms20064 KiB
#include <bits/stdc++.h> #define int long long #define ll long long #define pb push_back #define fi first #define se second #define lf (id<<1) #define rg ((id<<1)|1) #define md ((l+r)>>1) #define ld long double using namespace std; typedef pair<int,int> pii; typedef pair<char,char> pcc; typedef pair<int,pii> ipii; typedef pair<pii,pii> ipiii; const int MAXN = 5e5+30; const int SQRT = 610; const int MAXA = 5e3+10; const int MOD = 1e6+7; const int INF = 1e10+10; const int LOG = 21; const ld EPS = 1e-12; void chmx(int &a, int b){ a = max(a,b); } int n, u, d, s; vector <ipii> vec; int le[MAXN], ri[MAXN], le2[MAXN], ri2[MAXN], a[MAXN]; int QUE(int id){ return max(le[id]-id*u, ri[id]+id*d); } signed main(){ // ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n >> u >> d >> s; for(int i=0; i<=MAXA+3; i++) le[i] = ri[i] = -INF; for(int i=1; i<=s; i++) le[i] = -s*u; // -s*u + i*u for(int i=s; i<=MAXA; i++) ri[i] = s*d; // -i*d + s*d for(int i=1; i<=n; i++){ int d,id,w; cin>>d>>id>>w; vec.pb({d, {id,w}}); } sort(vec.begin(), vec.end()); for(int p=0; p<vec.size(); ){ int j = p; for(int i=1; i<=MAXA; i++) a[i] = 0; while(p<vec.size() && vec[p].fi == vec[j].fi){ a[vec[p].se.fi] += vec[p].se.se; p++; } int nw = -INF; for(int i=1; i<=MAXA; i++){ nw -= d; nw = max(nw, max(le[i]+i*u, ri[i]-i*d) ); nw += a[i]; ri2[i] = nw + i*d; } nw = -INF; for(int i=MAXA; i>=1; i--){ nw -= u; nw = max(nw, max(le[i]+i*u, ri[i]-i*d) ); nw += a[i]; le2[i] = nw - i*u; } for(int i=1; i<=MAXA; i++) chmx(le[i], max(le2[i], ri2[i]-i*d-i*u) ), chmx(ri[i], max(ri2[i], le2[i]+i*d+i*u) ); for(int i=1; i<=MAXA; i++){ // chmx(le[i], max(le[i+1], ri[i+1]-(i+1)*d-(i+1)*u)-u - i*u); chmx(le[i], le[i-1]-d-u); } for(int i=MAXA; i>=1; i--){ chmx(ri[i], ri[i+1]-d-u); // chmx(ri[i], max(ri[i-1], le[i-1]+(i-1)*d+(i-1)*u)-d + i*d); } // cout << max(le[s]+s*u, ri[s]-s*d) << '\n'; // for(int i=4; i<=21; i++) cout << le[i]+i*u << " \n"[i==21]; // for(int i=4; i<=21; i++) cout << ri[i]-i*d << " \n"[i==21]; } cout << max(le[s]+s*u, ri[s]-s*d) << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...