답안 #440508

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
440508 2021-07-02T10:58:27 Z MahfuzAhmed Pod starim krovovima (COCI20_psk) C++14
50 / 50
1 ms 332 KB
/**
 *  author: mahfuzz
 *  created: 02.07.2021
**/
 
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define all(p) p.begin(),p.end()
typedef long long ll;

bool cmp(pair<ll, ll> a, pair<ll, ll> b){
    if(a.first > b.first)
        return true;
        
    return false;
}
 
 
int main(int argc, char* argv[]){
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
	
    int n; cin >> n;
    
    vector<pair<ll, ll>> vec;
    ll sum = 0, arr[n];
    
    for(int i = 0; i < n; i++){
        ll x;
        cin >> x >> arr[i];
        
        sum += x;
        vec.push_back({arr[i], 0});
    }
    
    sort(all(vec), cmp);
    
    int cnt = 0;
    for(int i = 0; i < n; i++){
        vec[i].second = min(sum, vec[i].first);
        sum -= vec[i].second;
            
        if(vec[i].second == 0)
            ++cnt;
    }
    
    cout << cnt << "\n";
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(vec[j].first == arr[i]){
                vec[j].first = -1;
                cout << vec[j].second << " ";
                break;
            }
        }
    }
    
    cout << "\n";
 
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 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 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct