Submission #420466

#TimeUsernameProblemLanguageResultExecution timeMemory
420466JvThunderAutobahn (COI21_autobahn)C++17
0 / 100
1 ms204 KiB
#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,x; multiset<pair<pair<int,int>,int>> s; vector<pair<pair<int,int>,int>> val; void solve() { cin >> n >> k >> x; 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}); } priority_queue<pair<int,int>> pq; int cnt = 0; int prv = 0; for(auto x:s) { while(!pq.empty() && -pq.top().fir<x.fir.fir) { if(prv<-pq.top().fir && pq.size()>=k) val.pb({{prv,-pq.top().fir},cnt}); prv = -pq.top().fir+1; if(pq.top().sec==1) cnt--; pq.pop(); } if(prv<x.fir.fir-1 && pq.size()>=k) val.pb({{prv,x.fir.fir-1},cnt}); prv = x.fir.fir; pq.push({-x.fir.sec,x.sec}); if(x.sec==1) cnt++; } while(!pq.empty()) { if(prv<-pq.top().fir && pq.size()>=k) val.pb({{prv,-pq.top().fir},cnt}); prv = -pq.top().fir+1; if(pq.top().sec==1) cnt--; pq.pop(); } 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+x) { 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+x-val[ptr2+1].fir.fir); mxsum = max(mxsum,sum+left); 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-x)); 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+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 (stderr)

autobahn.cpp: In function 'void solve()':
autobahn.cpp:31:46: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   31 |             if(prv<-pq.top().fir && pq.size()>=k) val.pb({{prv,-pq.top().fir},cnt});
      |                                     ~~~~~~~~~^~~
autobahn.cpp:36:40: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   36 |         if(prv<x.fir.fir-1 && pq.size()>=k) val.pb({{prv,x.fir.fir-1},cnt});
      |                               ~~~~~~~~~^~~
autobahn.cpp:44:42: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   44 |         if(prv<-pq.top().fir && pq.size()>=k) val.pb({{prv,-pq.top().fir},cnt});
      |                                 ~~~~~~~~~^~~
autobahn.cpp:53:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |     for(int ptr=0;ptr<val.size();ptr++)
      |                   ~~~^~~~~~~~~~~
autobahn.cpp:55:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         while(ptr2+1<val.size() && val[ptr2+1].fir.sec<val[ptr].fir.fir+x)
      |               ~~~~~~^~~~~~~~~~~
autobahn.cpp:61:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |         if(ptr2+1>=val.size())
      |            ~~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...