# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
895569 | presko | Schools (IZhO13_school) | C++14 | 96 ms | 10164 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<iostream>
#include<bits/stdc++.h>
#define MAXN 300010
using namespace std;
pair<int,int> city[MAXN];
vector<pair<int,int>> order;
vector<pair<int,int>> var;
bool used1[MAXN];
bool used2[MAXN];
int main()
{
int n,m,s;
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n>>m>>s;
for(int i=1;i<=n;i++)
{
cin>>city[i].first>>city[i].second;
order.push_back({city[i].first,i});
var.push_back({city[i].second,i});
}
sort(order.begin(),order.end(),greater<pair<int,int>>());
sort(var.begin(),var.end(),greater<pair<int,int>>());
long long ans1=0,ans2=0;
for(int i=0;i<m;i++)
{
int mus=order[i].first;
int ind=order[i].second;
ans1+=mus;
used1[ind]=1;
}
int cntr=s;
for(int i=0;i<var.size();i++)
{
int sp=var[i].first;
int ind=var[i].second;
if(used1[ind]==0)
{
ans1+=sp;
cntr--;
}
if(cntr==0)break;
}
for(int i=0;i<s;i++)
{
int sp=var[i].first;
int ind=var[i].second;
ans2+=sp;
used2[ind]=1;
}
cntr=m;
for(int i=0;i<order.size();i++)
{
int mus=order[i].first;
int ind=order[i].second;
if(used2[ind]==0)
{
ans2+=mus;
cntr--;
}
if(cntr==0)break;
}
if(ans1<=ans2)cout<<ans2<<"\n";
else cout<<ans1<<"\n";
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |