Submission #791135

#TimeUsernameProblemLanguageResultExecution timeMemory
791135shoryu386Exhibition (JOI19_ho_t2)C++17
100 / 100
44 ms5576 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n, m; cin >> n >> m;
	pair<int, int> p[n]; int frame[m]; 
	for (int x = 0; x < n; x++) cin >> p[x].second >> p[x].first; //value, then size, easier
	for (int x = 0; x < m; x++) cin >> frame[x];
	
	sort(frame, frame+m, greater<int>()); //sort in decreasing size
	//we will construct ans from back to front
	//thus size monotonically decreases (sorted)
	//and value also monotonically decreases
	
	sort(p, p+n, greater<pair<int, int>>());

	int ptr = 0, usedFrames = 0;
	while (ptr != n){
		//if it fits, we put it in
		if (usedFrames >= m) break;
		if (frame[usedFrames] >= p[ptr].second){
			//can fit
			usedFrames++;
			ptr++;
		}
		else{
			ptr++; //cannot fit, try next one
		}
	}
	cout << usedFrames;
	
}

Compilation message (stderr)

joi2019_ho_t2.cpp:4:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    4 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...