Submission #725498

#TimeUsernameProblemLanguageResultExecution timeMemory
725498vjudge1Schools (IZhO13_school)C++17
5 / 100
105 ms5196 KiB
#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 timeMemoryGrader output
Fetching results...