답안 #700654

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
700654 2023-02-19T08:04:04 Z Polaris 학교 설립 (IZhO13_school) C++17
10 / 100
135 ms 8200 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

typedef long long ll;
typedef pair<int,int> p;

struct compare {
    bool operator() (p a,p b) {
        int ma = max(a.first,a.second);
        int mb = max(b.first,b.second);
        if(ma == mb)
            return a.first+a.second < b.first+b.second;
        return ma < mb;
    }
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int N,M,S;
    cin >> N >> M >> S;
    
    priority_queue<p,vector<p>,compare> city;
    for(int i=0; i<N; i++) {
        int a,b;
        cin >> a >> b;
        city.push({a,b});
    }
    
    vector<int> music;
    vector<int> sport;
    int m2 = M;
    int s2 = S;
    while(!city.empty()) {
        p f = city.top();
        city.pop();
        
        if(m2+s2 == 0)
            break;
        if(!m2) {
            sport.push_back(f.second);
            continue;
        } else if(!s2) {
            music.push_back(f.first);
            continue;
        }
        
        p s = city.top();
        if(f.first + s.second > f.second + s.first) {
            m2--;
            music.push_back(f.first);
        } else if(f.second + s.first > f.first + s.second) {
            s2--;
            sport.push_back(f.second);
        } else {
            if(f.first > f.second) {
                m2--;
                music.push_back(f.first);
            } else if(f.first < f.second) {
                s2--;
                sport.push_back(f.second);
            } else {
                if(m2 > s2) {
                    m2--;
                    music.push_back(f.first);
                } else {
                    s2--;
                    sport.push_back(f.second);
                }
            }
        }
    }
    
    sort(music.begin(),music.end(),greater<int>());
    sort(sport.begin(),sport.end(),greater<int>());
    ll ans = 0;
    for(int i=0; i<M; i++) {
        ans += music[i];
    }
    for(int i=0; i<S; i++) {
        ans += sport[i];
    }
    cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Incorrect 1 ms 212 KB Output isn't correct
7 Incorrect 3 ms 376 KB Output isn't correct
8 Incorrect 3 ms 472 KB Output isn't correct
9 Incorrect 2 ms 468 KB Output isn't correct
10 Incorrect 4 ms 464 KB Output isn't correct
11 Incorrect 3 ms 396 KB Output isn't correct
12 Incorrect 2 ms 464 KB Output isn't correct
13 Incorrect 17 ms 1388 KB Output isn't correct
14 Incorrect 39 ms 2640 KB Output isn't correct
15 Incorrect 76 ms 4892 KB Output isn't correct
16 Incorrect 118 ms 5460 KB Output isn't correct
17 Incorrect 95 ms 6812 KB Output isn't correct
18 Incorrect 132 ms 7024 KB Output isn't correct
19 Incorrect 123 ms 7420 KB Output isn't correct
20 Incorrect 135 ms 8200 KB Output isn't correct