# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
208317 | mohamedsobhi777 | Schools (IZhO13_school) | C++14 | 365 ms | 15224 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std ;
const int N = 1e6 + 7 , mod = 998244353;
long long n , A , B;
long long a[N] , b[N] ;
long long ans ;
int gA , gB ;
priority_queue<pair< pair<long long , long long > , int > > q1 , q2 ;
int main()
{
//freopen("in.in" , "r" , stdin) ;
cin>>n>>A>>B ;
for(int i = 0 ; i < n ; i++){
cin>>a[i] >> b[i] ;
if(a[i]>=b[i]){
q1.push({ { b[i], b[i] -a[i]},i });
}
else {
q2.push({{ a[i] , a[i] - b[i] }, i}) ;
}
ans += max(a[i] , b[i] ) ;
}
while(q1.size()> A && q2.size() < B){
ans+=q1.top().first.second ;
q2.push({ { a[q1.top().second] ,a[q1.top().second] - b[q1.top().second] },q1.top().second });
q1.pop();
}
while(q2.size()> B && q1.size() < A){
ans+=q2.top().first.second ;
q1.push({ {b[q2.top().second] , b[q2.top().second] - a[q2.top().second]} , q2.top().second}) ;
q2.pop();
}
if(q1.size() > A){
gA = q1.size() -A ;
priority_queue<long long> aux ;
while(q1.size()){
aux.push(-a[q1.top().second]) ;
q1.pop() ;
}
while(gA--){
ans+=aux.top() ;
aux.pop();
}
}
if(q2.size() > B){
gB = q2.size() -B ;
priority_queue<long long> aux ;
while(q2.size()){
aux.push(-b[q2.top().second]) ;
q2.pop() ;
}
while(gB--){
ans+=aux.top() ;
aux.pop();
}
}
cout<<ans;
return 0 ;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |