답안 #117200

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
117200 2019-06-15T10:23:50 Z Namnamseo Hotel (CEOI11_hot) C++17
50 / 100
847 ms 72520 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);
		}
	}

	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); }
                    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 15972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 16000 KB Output is correct
2 Correct 14 ms 16000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 16028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 16000 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 16896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 19004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 121 ms 21076 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 327 ms 30088 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 421 ms 43572 KB Output is correct
2 Correct 549 ms 72520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 453 ms 49848 KB Output is correct
2 Incorrect 847 ms 51320 KB Output isn't correct
3 Halted 0 ms 0 KB -