Submission #89133

#TimeUsernameProblemLanguageResultExecution timeMemory
89133nikolapesic2802Arranging Tickets (JOI17_arranging_tickets)C++14
0 / 100
11 ms8188 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> #define ll long long #define pb push_back #define sz(x) (int)(x).size() #define mp make_pair #define f first #define s second #define all(x) x.begin(), x.end() using namespace std; using namespace __gnu_pbds; using namespace __gnu_cxx; template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key() template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; } template<class T> ostream& operator<<(ostream& os, const vector<T>& a) { os << '{'; for(int i=0;i<sz(a);i++) { if(i>0&&i<sz(a)-1) os << ", "; os << a[i]; } os << '}'; return os; } const int N=2e5+100; vector<vector<pair<int,int> > > interval(N); vector<ll> sum(N),temp(N); int n; bool test(ll use, ll up) { for(int i=0;i<=n;i++) temp[i]=0; ll cnt=0; priority_queue<pair<int,int> > q; for(int i=1;i<=n;i++) { temp[i]+=temp[i-1]; for(auto p:interval[i]) q.push(p); ll now=sum[i]+temp[i]; //printf("NOW! %lld %i %lld %lld\n",now,i,sum[i],temp[i]); while(!q.empty()&&now>up) { int y,c; tie(y,c)=q.top(); q.pop(); if(y<=i) continue; ll v=min((ll)c,(ll)(now-up+1)/2); cnt+=v; temp[i]-=2*v; temp[y]+=2*v; now-=2*v; if(v<c) q.push({y,c-v}); } if(cnt>use||now>up) return false; } return true; } int main() { int m; scanf("%i %i",&n,&m); for(int i=0;i<m;i++) { int a,b,c; scanf("%i %i %i",&a,&b,&c); if(a>b) swap(a,b); interval[a].pb({b,c}); sum[a]+=c; sum[b]-=c; } ll maxV=0; for(int i=1;i<=n;i++) sum[i]+=sum[i-1],maxV=max(maxV,sum[i]); ll l=0,r=maxV; ll ans=-1; while(l<r) { ll mid=(l+r)>>1; if(test(maxV-mid,2*mid-maxV)||test(maxV-mid+1,2*mid-maxV-1)) r=mid-1,ans=mid; else l=mid+1; } printf("%lld\n",ans); return 0; }

Compilation message (stderr)

arranging_tickets.cpp: In function 'int main()':
arranging_tickets.cpp:71:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i %i",&n,&m);
     ~~~~~^~~~~~~~~~~~~~~
arranging_tickets.cpp:75:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i %i %i",&a,&b,&c);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~
#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...