Submission #250298

#TimeUsernameProblemLanguageResultExecution timeMemory
250298dtc03012학교 설립 (IZhO13_school)C++17
25 / 100
157 ms13032 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
typedef vector<int> vit;
typedef vector<vit> vitt;
typedef vector<lld> vlt;
typedef vector<vlt> vltt;
typedef vector<pi> vpit;
typedef vector<vpit> vpitt;
typedef long double ld;
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
bool isrange(int y,int x,int n,int m){
	 if(0<=y&&y<n&&0<=x&&x<m) return true;
	 return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};
pl arr[333333];
lld ans;
priority_queue<pair<lld,int> > q1;
priority_queue<lld> s;
bool tmr(pl a,pl b){
	if(a.x!=b.x) return a.x > b.x;
	return a.y > b.y;
}
int main(void){
	int n,a,b;
	scanf("%d%d%d",&n,&a,&b);
	for(int e=0;e<n;e++){
		lld a,b;
		scanf("%lld%lld",&a,&b);
		arr[e] = mk(a,b);
	}
	sort(arr,arr+n,tmr);
	for(int e=0;e<a;e++){
		ans += arr[e].x;
		q1.push(mk(-(arr[e].x-arr[e].y),e));
	}
	for(int e=a;e<n;e++){
		lld tt1 = arr[e].x - arr[e].y;
		if(sz(q1)==0) s.push(arr[e].y);
		else{
			lld tt2 = -q1.top().x;
			int wh = q1.top().y;
			if(tt2>=tt1) s.push(arr[e].y);
			else{
				ans += (arr[e].x-arr[wh].x);
				s.push(arr[wh].y);
				q1.pop();
				q1.push(mk(-tt1,e));
			}
		}
	}
	for(int e=0;e<b;e++){
		lld tt = s.top();
		ans += tt;
		s.pop();
	}
	printf("%lld",ans);
	return 0;
}

Compilation message (stderr)

school.cpp: In function 'int main()':
school.cpp:33:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d",&n,&a,&b);
  ~~~~~^~~~~~~~~~~~~~~~~~~
school.cpp:36:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld",&a,&b);
   ~~~~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...