# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
484933 |
2021-11-05T18:23:32 Z |
Bench0310 |
Hotel (CEOI11_hot) |
C++17 |
|
612 ms |
84380 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=500005;
vector<int> tree(4*N,0);
vector<int> lazy(4*N,0);
void pull(int idx)
{
tree[idx]=max(tree[2*idx],tree[2*idx+1]);
}
void apply(int idx,int x)
{
tree[idx]+=x;
lazy[idx]+=x;
}
void push(int idx)
{
for(int i=0;i<2;i++) apply(2*idx+i,lazy[idx]);
lazy[idx]=0;
}
void update(int idx,int l,int r,int ql,int qr,int x)
{
if(ql>qr) return;
if(l==ql&&r==qr) apply(idx,x);
else
{
int m=(l+r)/2;
push(idx);
update(2*idx,l,m,ql,min(qr,m),x);
update(2*idx+1,m+1,r,max(ql,m+1),qr,x);
pull(idx);
}
}
int descend(int idx,int l,int r)
{
if(l==r) return l;
int m=(l+r)/2;
push(idx);
if(tree[2*idx]>=tree[2*idx+1]) return descend(2*idx,l,m);
else return descend(2*idx+1,m+1,r);
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n,m,o;
cin >> n >> m >> o;
vector<array<int,2>> ini(n+1,{0,0});
for(int i=1;i<=n;i++) cin >> ini[i][1] >> ini[i][0];
sort(ini.begin(),ini.end());
vector<int> p(n+1,0);
vector<int> c(n+2,0);
c[n]=(1<<30);
for(int i=1;i<=n;i++)
{
p[i]=ini[i][0];
c[i]=ini[i][1];
}
vector<bool> vis(n+1,0);
vector<int> v[n+1];
for(int i=1;i<=n;i++) v[i].push_back(0);
for(int i=0;i<m;i++)
{
int x,d;
cin >> x >> d;
int t=(lower_bound(p.begin(),p.end(),d)-p.begin());
if(t<=n) v[t].push_back(x);
}
for(int i=1;i<=n;i++) sort(v[i].begin(),v[i].end());
for(int i=1;i<=n;i++) update(1,1,n,i,i,v[i].back()-c[i]);
set<int> s;
for(int i=0;i<=n+1;i++) s.insert(i);
auto prv=[&](int x)->int
{
auto it=s.lower_bound(x);
return (*prev(it));
};
auto nxt=[&](int x)->int
{
auto it=s.lower_bound(x);
return (*it);
};
ll res=0;
while(o--)
{
int mx=tree[1];
if(mx<0) break;
res+=mx;
int i=descend(1,1,n);
int d=(-v[i].back()+v[i][(int)v[i].size()-2]);
update(1,1,n,i,i,d);
v[i].pop_back();
s.erase(i);
int r=nxt(i);
int l=prv(i);
update(1,1,n,l+1,i,c[i]-c[r]);
}
cout << res << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
15948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
15972 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
15948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
15948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
17100 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
68 ms |
20812 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
128 ms |
24592 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
411 ms |
42172 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
529 ms |
71588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
612 ms |
84380 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |