답안 #440460

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
440460 2021-07-02T10:05:37 Z mashrur_hossain Pod starim krovovima (COCI20_psk) C++14
50 / 50
1 ms 348 KB
#include <bits/stdc++.h>

#define fast_cin         ios_base::sync_with_stdio(0); cin.tie(NULL); cerr.tie(NULL);
#define endl "\n"
#define dbg(x) cerr << #x << ": " << x << endl;
#define DBG    cerr << __LINE__ << ": I GOT STUCK\n";

using namespace std;    
typedef long long ll;
typedef long double db;
 

void solve(){
    ll n;cin >> n;
    ll tot = 0;
    vector<pair<ll, ll>>v;
    for(ll i = 0;i<n;i++){
        ll t,z;cin >> t >> z;
        tot += t;
        v.emplace_back(z, i);
    }
    sort(v.rbegin(), v.rend());
    vector<ll>ans(n, 0);
    for(ll i = 0;i<n;i++){
        if(tot > v[i].first){
            // fill it up
            ans[v[i].second] = v[i].first;
            tot -= v[i].first;
        }
        else{
            // the rest are empty
            ans[v[i].second] = tot;
            break;
        }
    }
    ll cnt = 0;
    for(ll i = 0;i<n;i++){
        if(ans[i] == 0)cnt++;
    }
    cout << cnt << endl;
    for(ll i = 0;i<n;i++){
        cout << ans[i] << " \n"[i==n-1];
    }
}  


int main() {
    fast_cin;
    int test;test = 1;
    // int test;cin >>test;
    while(test--){
        solve();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 332 KB Output is correct