Submission #47566

# Submission time Handle Problem Language Result Execution time Memory
47566 2018-05-05T03:52:29 Z dqhungdl Schools (IZhO13_school) C++17
100 / 100
269 ms 15344 KB
#include <bits/stdc++.h>
using namespace std;

typedef pair<long long,long long> ii;
long long n,A,B,res=0,f1[300005],f2[300005];
ii a[300005];
multiset<long long> s;

bool cmp(ii x1,ii x2)
{
	return x1.first-x1.second>x2.first-x2.second;
}

int main()
{
	ios_base::sync_with_stdio(false);
	//freopen("TEST.INP","r",stdin);
	//freopen("TEST.OUT","w",stdout);
	cin>>n>>A>>B;
	for(long long i=1;i<=n;i++)
		cin>>a[i].first>>a[i].second;
	sort(a+1,a+n+1,cmp);
	long long sum=0;
	for(long long i=1;i<=n;i++)
	{
		sum+=a[i].first;
		s.insert(a[i].first);
		if(s.size()>A)
		{
			sum-=*s.begin();
			s.erase(s.begin());
		}
		f1[i]=sum;
	}
	s.clear();
	sum=0;
	for(long long i=n;i>=1;i--)
	{
		sum+=a[i].second;
		s.insert(a[i].second);
		if(s.size()>B)
		{
			sum-=*s.begin();
			s.erase(s.begin());
		}
		f2[i]=sum;
	}
	for(long long i=A;i<=n-B;i++)
		res=max(res,f1[i]+f2[i+1]);
	cout<<res;
}

Compilation message

school.cpp: In function 'int main()':
school.cpp:28:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(s.size()>A)
      ~~~~~~~~^~
school.cpp:41:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(s.size()>B)
      ~~~~~~~~^~
# 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 460 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 2 ms 672 KB Output is correct
7 Correct 5 ms 740 KB Output is correct
8 Correct 4 ms 1028 KB Output is correct
9 Correct 4 ms 1028 KB Output is correct
10 Correct 4 ms 1028 KB Output is correct
11 Correct 5 ms 1028 KB Output is correct
12 Correct 5 ms 1028 KB Output is correct
13 Correct 28 ms 3180 KB Output is correct
14 Correct 53 ms 4076 KB Output is correct
15 Correct 81 ms 5836 KB Output is correct
16 Correct 170 ms 13804 KB Output is correct
17 Correct 205 ms 13804 KB Output is correct
18 Correct 216 ms 13804 KB Output is correct
19 Correct 246 ms 13804 KB Output is correct
20 Correct 269 ms 15344 KB Output is correct