답안 #117192

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
117192 2019-06-15T09:28:34 Z Namnamseo Hotel (CEOI11_hot) C++17
0 / 100
374 ms 28424 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()) { on.insert(i); S.emplace(pq[i].top() - room[i].x, 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;
			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 Incorrect 16 ms 16000 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 16000 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 15 ms 16000 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 18 ms 16000 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 21 ms 16376 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 46 ms 17316 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 68 ms 18340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 161 ms 21760 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 315 ms 27200 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 374 ms 28424 KB Output isn't correct
2 Halted 0 ms 0 KB -