답안 #198716

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
198716 2020-01-27T13:06:02 Z socho Pod starim krovovima (COCI20_psk) C++14
50 / 50
7 ms 504 KB
#include "bits/stdc++.h"
using namespace std;
 
int main() {
    
    long long n;
    cin >> n;
    
    long long sm = 0;
    vector<pair<long long, long long> > gls;
    for (long long i=0; i<n; i++) {
        long long amount, cap;
        cin >> amount >> cap;
        gls.push_back(make_pair(cap, i));
        sm += amount;
    }
    
    sort(gls.begin(), gls.end());
    reverse(gls.begin(), gls.end());
    
    long long take[n];
    memset(take, 0, sizeof take);
    
    long long zr = 0;
    for (long long i=0; i<n; i++) {
        long long ca = gls[i].first, at = gls[i].second;
        long long ta = min(ca, sm);
        sm -= ta;
        take[at] = ta;
        if (ta == 0) zr++;
    }
    
    cout << zr << endl;
    for (long long i=0; i<n; i++) {
        cout << take[i] << ' ';
    }
    cout << endl;
    
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 6 ms 376 KB Output is correct
9 Correct 6 ms 504 KB Output is correct
10 Correct 7 ms 376 KB Output is correct