답안 #431814

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
431814 2021-06-17T15:46:04 Z Habitus 학교 설립 (IZhO13_school) C++14
25 / 100
399 ms 36380 KB
#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define dec(x, y) fixed << setprecision((y)) << (x)
#define xx first
#define yy second
#define srt(v) sort((v).begin(), (v).end())
#define srtr(v) sort((v).rbegin(), (v).rend())
#define pb push_back
#define popb pop_back
#define sz(a) (int)(a).size()
#define len(a) (int)(a).length()
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int n, m, s;
pll x[300010];
set<pll> naja, najb, raz;
ll rez;
int main() {
    ios;
    cin >> n >> m >> s;
    for(int i=0; i<n; ++i) {
        cin >> x[i].xx >> x[i].yy;
    }
    sort(x, x+n, greater<pll>());
    for(int i=0; i<m; ++i) {
        rez+=x[i].xx;
        raz.insert({x[i].yy-x[i].xx, (ll)i});
    }
    for(int i=m; i<n; ++i) {
        naja.insert({x[i].xx, (ll)i});
        najb.insert({x[i].yy, (ll)i});
    }
    int br=0;
    while(true) {
        ++br;
        if(s==0) break;
        pll pr=*prev(najb.end());
        pll dr=*prev(raz.end());
        pll tr=*prev(naja.end());
        if(pr.xx>dr.xx+tr.xx && pr.xx>0LL) {
            rez+=pr.xx;
            --s;
            if(!najb.empty()) najb.erase(prev(najb.end()));
            auto it=naja.find({x[pr.yy].xx, pr.yy});
            if(it!=naja.end() && !naja.empty()) naja.erase(it);
        }
        else if(dr.xx+tr.xx>0LL) {
            rez+=dr.xx+tr.xx;
            --s;
            if(!raz.empty()) raz.erase(prev(raz.end()));
            if(!naja.empty()) naja.erase(prev(naja.end()));
            raz.insert({x[tr.yy].yy-x[tr.yy].xx, tr.yy});
        }
        else break;
        //if(br>=1000000) {cout << 1; break;}
    }
    cout << rez;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Incorrect 1 ms 204 KB Output isn't correct
5 Correct 1 ms 204 KB Output is correct
6 Incorrect 1 ms 332 KB Output isn't correct
7 Incorrect 5 ms 844 KB Output isn't correct
8 Incorrect 3 ms 588 KB Output isn't correct
9 Incorrect 3 ms 716 KB Output isn't correct
10 Incorrect 3 ms 716 KB Output isn't correct
11 Incorrect 5 ms 972 KB Output isn't correct
12 Incorrect 5 ms 972 KB Output isn't correct
13 Incorrect 24 ms 3404 KB Output isn't correct
14 Incorrect 100 ms 10816 KB Output isn't correct
15 Correct 250 ms 22640 KB Output is correct
16 Incorrect 384 ms 24260 KB Output isn't correct
17 Incorrect 287 ms 25836 KB Output isn't correct
18 Incorrect 292 ms 28364 KB Output isn't correct
19 Incorrect 358 ms 31052 KB Output isn't correct
20 Incorrect 399 ms 36380 KB Output isn't correct