Submission #259832

# Submission time Handle Problem Language Result Execution time Memory
259832 2020-08-08T15:58:47 Z uacoder123 Hotel (CEOI11_hot) C++14
100 / 100
964 ms 58804 KB
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) lli(x.size())
#define mp(i,a) make_pair(i,a)
#define pb(a) push_back(a)
#define bit(x,b) (x&(1LL<<b))

typedef long long int lli;
typedef pair <lli,lli> ii;
typedef pair <lli,ii> iii;
typedef vector <lli> vi;
vector<ii> q,h;
bool cmp(ii a,ii b)
{
	if(a.F==b.F)
		return a.S>b.S;
	else
		return a.F<b.F;
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  lli n,m,o,j=-1,co=0,ans=0;
  cin>>n>>m>>o;
  for(lli i=0;i<n;++i)
  {
  	lli f,s;
  	cin>>f>>s;
  	h.pb(mp(s,f));
  }
  sort(all(h));
  for(lli i=0;i<m;++i)
  {
  	lli f,s;
  	cin>>f>>s;
  	q.pb(mp(s,f));
  }
  sort(all(q),cmp);
  multiset<lli> s,s1;
  for(lli i=0;i<n;++i)
  {
  	while(j!=q.size()-1&&q[j+1].F<=h[i].F)
  	{
  		j++;
  		s.insert(q[j].S);
  	}
  	if(s.size())
  	{
  		s1.insert((*(--s.end()))-h[i].S);
  		s.erase(--s.end());
  	}
  }
  if(s1.size())
  {
  	auto it=(s1.end());
  	while(co<o)
  	{
  		if(it==s1.begin())
  			break;
  		it--;
  		ans+=max(0*1LL,(*it));
  		co++;
  	}
  }
  cout<<ans<<endl;
  return(0);
}

Compilation message

hot.cpp: In function 'int main()':
hot.cpp:48:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    while(j!=q.size()-1&&q[j+1].F<=h[i].F)
          ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 5004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 113 ms 8548 KB Output is correct
2 Correct 64 ms 5776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 335 ms 23712 KB Output is correct
2 Correct 216 ms 17628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 711 ms 47044 KB Output is correct
2 Correct 731 ms 47172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 857 ms 55664 KB Output is correct
2 Correct 964 ms 58804 KB Output is correct
3 Correct 947 ms 56004 KB Output is correct