답안 #546739

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
546739 2022-04-08T10:49:45 Z someone Pod starim krovovima (COCI20_psk) C++14
50 / 50
1 ms 340 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

struct Val {
    int val, i, vol;
};
 
const int N = 1e5 + 42, INF = 1e18 + 42;

Val val[N];
int n, sum = 0, nb = 0;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> val[i].val >> val[i].vol;
        sum += val[i].val;
        val[i].i = i;
    }
    
    sort(val, val + n,
    [](Val a, Val b) {
        return a.vol > b.vol;
    });
    
    for(int i = 0; i < n; i++) {
        val[i].val = min(val[i].vol, sum);
        sum -= val[i].val;
        if(val[i].val == 0)
            nb++;
    }
    
    sort(val, val + n,
    [](Val a, Val b) {
        return a.i < b.i;
    });
    
    cout << nb << '\n';
    for(int i = 0; i < n; i++)
        cout << val[i].val << ' ';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct