Submission #204605

# Submission time Handle Problem Language Result Execution time Memory
204605 2020-02-26T11:36:04 Z MohamedAhmed04 Schools (IZhO13_school) C++14
100 / 100
146 ms 16088 KB
#include <bits/stdc++.h>

using namespace std ;

const int MAX = 3e5 + 10 ;

long long music[MAX] , sport[MAX] ;
long long pref[MAX] , suff[MAX] ;
int n , m , s ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n>>m>>s ;
	vector< pair<int , pair<int , int> > >vp ;
	for(int i = 1 ; i <= n ; ++i)
	{
		cin>>music[i]>>sport[i] ;
		vp.push_back({music[i] - sport[i] , {music[i] , sport[i]}}) ;
	}
	sort(vp.rbegin() , vp.rend()) ;
	for(int i = 1 ; i <= n ; ++i)
		music[i] = vp[i-1].second.first , sport[i] = vp[i-1].second.second ;
	priority_queue<int , vector<int> , greater<int> >q ;
	long long now = 0ll ;
	for(int i = 1 ; i <= n ; ++i)
	{
		if(q.size() >= m && q.size() > 0 && q.top() < music[i])
		{
			now -= q.top() ;
			q.pop() ;
			now += music[i] * 1ll ;
			q.push(music[i]) ;
		}
		else if(q.size() < m)
		{
			now += music[i] * 1ll ;
			q.push(music[i]) ;
		}
		if(q.size() == m)
			pref[i] = now ;
	}
	while(!q.empty())
		q.pop() ;
	now = 0ll ;
	for(int i = n ; i >= 1 ; --i)
	{
		if(q.size() >= s && q.size() > 0 && q.top() < sport[i])
		{
			now -= q.top() ;
			q.pop() ;
			now += sport[i] * 1ll ;
			q.push(sport[i]) ;
		}
		else if(q.size() < s)
		{
			now += sport[i] * 1ll ;
			q.push(sport[i]) ;
		}
		if(q.size() == s)
			suff[i] = now ;
	}
	long long ans = 0ll ;
	for(int i = 0 ; i <= n ; ++i)
		ans = max(ans , pref[i] + suff[i+1]) ;
	return cout<<ans<<"\n" , 0 ;
}		

Compilation message

school.cpp: In function 'int main()':
school.cpp:29:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(q.size() >= m && q.size() > 0 && q.top() < music[i])
      ~~~~~~~~~^~~~
school.cpp:36:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   else if(q.size() < m)
           ~~~~~~~~~^~~
school.cpp:41:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(q.size() == m)
      ~~~~~~~~~^~~~
school.cpp:49:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(q.size() >= s && q.size() > 0 && q.top() < sport[i])
      ~~~~~~~~~^~~~
school.cpp:56:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   else if(q.size() < s)
           ~~~~~~~~~^~~
school.cpp:61:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(q.size() == s)
      ~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 380 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 6 ms 632 KB Output is correct
8 Correct 7 ms 632 KB Output is correct
9 Correct 8 ms 732 KB Output is correct
10 Correct 7 ms 632 KB Output is correct
11 Correct 8 ms 632 KB Output is correct
12 Correct 7 ms 632 KB Output is correct
13 Correct 22 ms 2288 KB Output is correct
14 Correct 37 ms 4712 KB Output is correct
15 Correct 62 ms 9060 KB Output is correct
16 Correct 83 ms 10340 KB Output is correct
17 Correct 112 ms 11872 KB Output is correct
18 Correct 125 ms 13156 KB Output is correct
19 Correct 131 ms 14048 KB Output is correct
20 Correct 146 ms 16088 KB Output is correct