Submission #117202

# Submission time Handle Problem Language Result Execution time Memory
117202 2019-06-15T10:26:52 Z Namnamseo Hotel (CEOI11_hot) C++17
100 / 100
1831 ms 69796 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
void read(pp& x){ scanf("%d%d",&x.first, &x.second); }
void read(pll& x){ scanf("%lld%lld",&x.first, &x.second); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
void cppio(){ ios_base::sync_with_stdio(0); cin.tie(0); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define sz(x) (int)(x).size()

const int inf = int(1e9) + 10;

int n, m;
const int maxn = int(5e5) + 10;

pp room[maxn];
pp req[maxn];

priority_queue<int> pq[maxn];
set<pp> S;

set<int> on;

int main()
{
	int o;
	cppio(); cin >> n >> m >> o;
	rrep(i, n) { cin >> room[i].x >> room[i].y; }
	rrep(i, m) { cin >> req[i].y >> req[i].x; }

	sort(room+1, room+n+1);
	sort(req+1, req+m+1);

	rrep(i, m) {
		static int pt = 1;
		while(pt<=n && room[pt].y < req[i].x) ++pt;
		if(pt > n) break;
		pq[pt].push(req[i].y);
	}

	rrep(i, n) if(pq[i].size()) { S.emplace(pq[i].top() - room[i].x, i); }
	rrep(i, n) on.insert(i);

	int match = 0;
	ll ans = 0;
	while(match < o && S.size()) {
		auto it = --S.end();
		if(it->x < 0) break;
		ans += it->x;
		int i = it->y;
		S.erase(it);

		++match;
		pq[i].pop();
		if(pq[i].size()) {
			auto it = on.erase(on.find(i));
			if(it == on.end()) continue;
			int j = *it;
			if(pq[j].size()) S.erase(pp(pq[j].top() - room[j].x, j));
			if(pq[i].size() > pq[j].size()) {
				swap(pq[i], pq[j]);
			}

			while(pq[i].size()) {
				pq[j].push(pq[i].top());
				pq[i].pop();
			}

			S.emplace(pq[j].top() - room[j].x, j);
		} else on.erase(i);
	}

	cout << ans << endl;

	return 0;
}

Compilation message

hot.cpp: In function 'void read(int&)':
hot.cpp:6:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 void read(int& x){ scanf("%d",&x); }
                    ~~~~~^~~~~~~~~
hot.cpp: In function 'void read(ll&)':
hot.cpp:7:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 void read(ll& x){ scanf("%lld",&x); }
                   ~~~~~^~~~~~~~~~~
hot.cpp: In function 'void read(pp&)':
hot.cpp:8:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 void read(pp& x){ scanf("%d%d",&x.first, &x.second); }
                   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
hot.cpp: In function 'void read(pll&)':
hot.cpp:9:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 void read(pll& x){ scanf("%lld%lld",&x.first, &x.second); }
                    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 16 ms 16000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 16000 KB Output is correct
2 Correct 15 ms 16000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 16000 KB Output is correct
2 Correct 15 ms 16004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 15960 KB Output is correct
2 Correct 15 ms 16000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 17024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 19268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 113 ms 21240 KB Output is correct
2 Correct 67 ms 21112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 322 ms 30112 KB Output is correct
2 Correct 125 ms 24696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 437 ms 43676 KB Output is correct
2 Correct 559 ms 57168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 514 ms 50008 KB Output is correct
2 Correct 845 ms 50544 KB Output is correct
3 Correct 1831 ms 69796 KB Output is correct