# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
420904 | 2021-06-08T14:45:53 Z | JvThunder | Autobahn (COI21_autobahn) | C++14 | 1 ms | 204 KB |
#include <bits/stdc++.h> #define pb push_back #define mp make_pair #define fir first #define sec second typedef long long ll; using namespace std; int n,k,z; multiset<pair<pair<int,int>,int>> s; vector<pair<pair<int,int>,int>> val; void solve() { cin >> n >> k >> z; set<int> all; for(int i=0;i<n;i++) { int l,t,r; cin >> l >> t >> r; s.insert({{l,l+t-1},0}); s.insert({{l+t,r},1}); all.insert(l); all.insert(l+t); all.insert(r+1); } priority_queue<pair<int,int>> pq; int cnt = 0; auto itr = s.begin(); int prv = (*itr).fir.fir; for(auto x:all) { if(pq.size()>=k) val.pb({{prv,x-1},cnt}); prv = x; while(!pq.empty() && -pq.top().fir<x) { if(pq.top().sec==1) cnt--; pq.pop(); } while(itr!=s.end() && (*itr).fir.fir<=x) { if((*itr).sec==1) cnt++; pq.push({-(*itr).fir.sec,(*itr).sec}); itr++; } } ll sum = 0; ll mxsum = 0; int ptr2 = -1; for(int ptr=0;ptr<val.size();ptr++) { while(ptr2+1<val.size() && val[ptr2+1].fir.sec<val[ptr].fir.fir+z) { ptr2++; sum += (ll)val[ptr2].sec*(val[ptr2].fir.sec-val[ptr2].fir.fir+1); } mxsum = max(sum,mxsum); if(ptr2+1>=val.size()) { sum -= (ll)val[ptr].sec*(val[ptr].fir.sec-val[ptr].fir.fir+1); continue; } ll left = (ll)val[ptr2+1].sec*(val[ptr].fir.fir+z-val[ptr2+1].fir.fir); ll all = (ll)val[ptr2+1].sec*(val[ptr2+1].fir.sec-val[ptr2+1].fir.fir+1); ll rem = (ll)val[ptr].sec*(val[ptr].fir.sec-(val[ptr2+1].fir.sec-z)); if(rem<0 || left<0 || all<0) { sum -= (ll)val[ptr].sec*(val[ptr].fir.sec-val[ptr].fir.fir+1); continue; } mxsum = max(mxsum,sum+left); mxsum = max(mxsum,sum+all-rem); sum -= (ll)val[ptr].sec*(val[ptr].fir.sec-val[ptr].fir.fir+1); } cout << mxsum << endl; return; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int tc=1; //cin>>tc; for(int i=1;i<=tc;i++) solve(); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 204 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 204 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 204 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |