답안 #84463

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
84463 2018-11-15T09:13:14 Z farukkastamonuda 학교 설립 (IZhO13_school) C++14
100 / 100
393 ms 31472 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define lo long long 
#define inf 1000000000
#define md 1000000007
#define pb push_back
#define li 300005
#define ii pair<lo int,lo int>
using namespace std;
lo int n,m,ss,cev;
pair<lo int,lo int> A[li];
priority_queue<lo int> q;
multiset< pair<lo int,lo int> > s,t;
int main(){
	scanf("%lld %lld %lld",&n,&m,&ss);
	for(int i=1;i<=n;i++){
		scanf("%lld %lld",&A[i].fi,&A[i].se);
	}
	sort(A+1,A+n+1);
	reverse(A+1,A+n+1);
	for(int i=1;i<=m;i++){
		cev+=A[i].fi;
		q.push(A[i].se-A[i].fi);
	}
	for(int i=m+1;i<=n;i++){
		s.insert(mp(A[i].fi,A[i].se));
		t.insert(mp(A[i].se,A[i].fi));
	}
	while(ss--){
		lo int fark=q.top();
		//q.pop();
		ii a=*s.rbegin();
		ii b=*t.rbegin();
		if(fark+a.fi>b.fi){
			cev+=fark+a.fi;
			q.pop();
			s.erase(s.find(a));
			t.erase(t.find(mp(a.se,a.fi)));
			q.push(a.se-a.fi);
		}
		else{
			cev+=b.fi;
			t.erase(t.find(b));
			s.erase(s.find(mp(b.se,b.fi)));
		}
	}
	printf("%lld\n",cev);
	return 0;
}

Compilation message

school.cpp: In function 'int main()':
school.cpp:17:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld %lld %lld",&n,&m,&ss);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
school.cpp:19:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld",&A[i].fi,&A[i].se);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
3 Correct 2 ms 508 KB Output is correct
4 Correct 2 ms 588 KB Output is correct
5 Correct 2 ms 588 KB Output is correct
6 Correct 2 ms 656 KB Output is correct
7 Correct 6 ms 1052 KB Output is correct
8 Correct 3 ms 1052 KB Output is correct
9 Correct 4 ms 1052 KB Output is correct
10 Correct 4 ms 1052 KB Output is correct
11 Correct 7 ms 1280 KB Output is correct
12 Correct 7 ms 1280 KB Output is correct
13 Correct 17 ms 1884 KB Output is correct
14 Correct 111 ms 10508 KB Output is correct
15 Correct 300 ms 22880 KB Output is correct
16 Correct 393 ms 23400 KB Output is correct
17 Correct 257 ms 23400 KB Output is correct
18 Correct 272 ms 23528 KB Output is correct
19 Correct 311 ms 26336 KB Output is correct
20 Correct 370 ms 31472 KB Output is correct