# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
204605 | MohamedAhmed04 | 학교 설립 (IZhO13_school) | C++14 | 146 ms | 16088 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 ;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |