Submission #391992

#TimeUsernameProblemLanguageResultExecution timeMemory
391992nicolaalexandraHotel (CEOI11_hot)C++14
20 / 100
855 ms28436 KiB
#include <bits/stdc++.h> #define DIM 500010 using namespace std; pair <int,int> v[DIM],w[DIM]; int aint[DIM*4]; int n,m,nr,i,sol; void build (int nod, int st, int dr){ if (st == dr){ aint[nod] = v[st].second; return; } int mid = (st+dr)>>1; build (nod<<1,st,mid); build ((nod<<1)|1,mid+1,dr); aint[nod] = max (aint[nod<<1],aint[(nod<<1)|1]); } void query (int nod, int st, int dr, int val){ if (st == dr){ sol = st; return; } int mid = (st+dr)>>1; if (aint[nod<<1] >= val) query (nod<<1,st,mid,val); else query ((nod<<1)|1,mid+1,dr,val); } void update (int nod, int st, int dr, int poz, int val){ if (st == dr){ aint[nod] = val; return; } int mid = (st+dr)>>1; if (poz <= mid) update (nod<<1,st,mid,poz,val); else update ((nod<<1)|1,mid+1,dr,poz,val); aint[nod] = max (aint[nod<<1],aint[(nod<<1)|1]); } inline int cmp (pair <int,int> a, pair <int,int> b){ if (a.first == b.first) return a.second < b.second; return a.first > b.first; } int main (){ //ifstream cin ("date.in"); //ofstream cout ("date.out"); cin>>n>>m>>nr; for (i=1;i<=n;i++) cin>>v[i].first>>v[i].second; for (i=1;i<=m;i++) cin>>w[i].first>>w[i].second; sort (v+1,v+n+1); build (1,1,n); sort (w+1,w+m+1,cmp); long long ans = 0; for (i=1;i<=m;i++){ if (aint[1] < w[i].second) continue; sol = 0; query (1,1,n,w[i].second); if (sol && v[sol].first < w[i].first){ ans += w[i].first - v[sol].first; update (1,1,n,sol,0); nr--; if (!nr) break; } } cout<<ans; return 0; }
#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...