# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
725498 | vjudge1 | Schools (IZhO13_school) | C++17 | 105 ms | 5196 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>
#define B begin()
#define rB rbegin()
#define E end()
#define rE rend()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ll long long
#define ui unsigned int
#define ull unsigned long long
#define sts stable_sort
using namespace std;
const int MAXN = 1e6 + 4;
const int MOD = 1e9 + 7;
bool comp[MAXN];
ll res = 0;
//void f(vector<pair<int, int> > v, vector<pair<int, int> > b, int m, int s, int n){
// for(int i = 0 ; i < n; i++){
// if(comp[i])continue;
// if(m == 0){
// for(int j = i; j < n && s > 0; j++){
// if(comp[j])continue;
// res += b[j];
// s--;
// }
// return;
// }else if(s == 0){
// for(int j = i; j < n && m > 0; j++){
// if(comp[j])continue;
// res += v[j];
// m--;
// }
// return;
// }
// if(v[i].S == b[i].S){
// if(v[i].F >= b[i].F){
// res += v[i].F;
// m--;
// comp[v[i].S] = 1;
// for(int j = i + 1; j < n; j++){
// if(comp[j])continue;
// res += b[j].F;
// comp[b[j].S] = 1;
// break;
// }
// }else{
// res += b[i].F;
// s--;
// comp[b[i].S] = 1;
// for(int j = i + 1; j < n; j++){
// if(comp[j])continue;
// res += v[j].F;
// comp[v[j].S] = 1;
// break;
// }
// }
// }else{
// if(v[i].S >= b[i].F){
// res +=
// comp[v[i].S] = 1;
// m--;
// }
// }
// }
//}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int n, M, S; cin >> n >> M >> S;
vector<pair<int, int> > v(n);
vector<pair<int, int> > b(n);
for(int i = 0; i < n; i++){
cin >> v[i].F; v[i].S = i;
cin >> b[i].F; b[i].S = i;
}
sort(v.rB, v.rE);
sort(b.rB, b.rE);
for(int i = 0; i < n; i++){
if(M == 0)break;
if(comp[v[i].S])continue;
res += v[i].F;
comp[v[i].S] = 1;
M--;
}
for(int i = 0; i < n; i++){
if(S == 0)break;
if(comp[b[i].S])continue;
res += b[i].F;
comp[b[i].S] = 1;
S--;
}
cout << res << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |