Submission #167111

# Submission time Handle Problem Language Result Execution time Memory
167111 2019-12-06T03:27:52 Z abil Schools (IZhO13_school) C++14
100 / 100
281 ms 13976 KB
#include <bits/stdc++.h>

#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define all(s) s.begin(),s.end()
//#define int long long

using namespace std;

const int N = (3e5 + 12);
const int mod = (1e9 + 7);
const int INF = (0x3f3f3f3f);

pair<int,pair<int,int > > a[N];
multiset<int > st;
long long pr[N], sf[N];

main()
{
	int n, m, s;
	long long sum = 0;
	scanf("%d%d%d", &n, &m, &s);
	for(int i = 1;i <= n; i++){
		scanf("%d%d", &a[i].sc.fr, &a[i].sc.sc);
		a[i].fr = a[i].sc.sc - a[i].sc.fr;
 	}
 	sort(a + 1,a + 1 + n);
 	for(int i = 1;i <= n; i++){
		sum += a[i].sc.fr;
		st.insert(a[i].sc.fr);
		if(i > m){
			sum -= *st.begin();
			st.erase(st.begin());
		}
		pr[i] = sum;
 	}
	st.clear();
	sum = 0;
	for(int i = n;i >= 1; i--){
		sum += a[i].sc.sc;
		st.insert(a[i].sc.sc);
		if(i <= n - s){
			sum -= *st.begin();
			st.erase(st.begin());
		}
		sf[i] = sum;
	}
	long long ans = 0;
	for(int i = max(1, m);i <= n - s; i++){
		ans = max(ans, pr[i] + sf[i + 1]);
	}
	cout << ans;
}

Compilation message

school.cpp:20:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
school.cpp: In function 'int main()':
school.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &n, &m, &s);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
school.cpp:26:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &a[i].sc.fr, &a[i].sc.sc);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 4 ms 504 KB Output is correct
8 Correct 5 ms 632 KB Output is correct
9 Correct 5 ms 632 KB Output is correct
10 Correct 5 ms 632 KB Output is correct
11 Correct 5 ms 632 KB Output is correct
12 Correct 5 ms 632 KB Output is correct
13 Correct 30 ms 2808 KB Output is correct
14 Correct 52 ms 3420 KB Output is correct
15 Correct 84 ms 4968 KB Output is correct
16 Correct 194 ms 12636 KB Output is correct
17 Correct 223 ms 11384 KB Output is correct
18 Correct 223 ms 11256 KB Output is correct
19 Correct 244 ms 12408 KB Output is correct
20 Correct 281 ms 13976 KB Output is correct