제출 #1129871

#제출 시각아이디문제언어결과실행 시간메모리
1129871ByeWorldSails (IOI07_sails)C++20
30 / 100
1095 ms2488 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3") #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 = 1e5+10; const int MAXA = 1e6; const int INF = 1e18+10; const int MOD = 1e9+7; const int LOG = 32; const ld EPS = 1e-12; int n, ans; set <pii> pq; signed main(){ // ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n; vector<pii> vec; for(int i=1; i<=n; i++){ int x, y; cin>>x>>y; vec.pb({x,y}); } sort(vec.begin(), vec.end()); pq.insert({MAXN+1, INF}); int las = MAXN+1, p = 0; for(auto [x,y] : vec){ if(x!=p){ pq.insert(pii(las-(x-p), 0)); las = las-(x-p); p = x; } // cout << x << ' '<< y << "xy\n"; // masukin y vector <pii> te; int sis = y; while(sis != 0){ pii sta = *pq.begin(); pq.erase(pq.begin()); pii en = *pq.begin(); if(sis >= en.fi-sta.fi){ ans += (en.fi-sta.fi) * sta.se; te.pb({sta.fi, sta.se+1}); sis -= en.fi-sta.fi; } else { ans += sis * sta.se; te.pb({sta.fi, sta.se}); te.pb({en.fi-sis, sta.se+1}); sis = 0; } } te.pb(*pq.begin()); pq.erase(pq.begin()); for(auto in : te){ auto it = pq.lower_bound(in); if(it==pq.begin()) pq.insert(in); else { it--; if((*it).se != in.se) pq.insert(in); // gk ush masukin kalo sama } } // for(auto [p,q] : pq) cout << p << ' ' << q << " xy\n"; } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...