Submission #868760

# Submission time Handle Problem Language Result Execution time Memory
868760 2023-11-02T00:49:30 Z Pring Pod starim krovovima (COCI20_psk) C++14
50 / 50
1 ms 348 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define fs first
#define sc second
#define mp make_pair
typedef pair<int, int> pii;
typedef pair<pii, int> p3i;

const int MXN = 1005;
int n, sum;
p3i p[MXN];

void miku() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> p[i].fs.sc >> p[i].fs.fs;
        sum += p[i].fs.sc;
        p[i].fs.sc = 0;
        p[i].sc = i;
    }
    sort(p, p + n, greater<p3i>());
    for (int i = 0; i < n; i++) {
        if (sum >= p[i].fs.fs) {
            p[i].fs.sc = p[i].fs.fs;
            sum -= p[i].fs.fs;
        } else {
            p[i].fs.sc = sum;
            break;
        }
    }
    sort(p, p + n, [](p3i a, p3i b) -> bool {
        return a.sc < b.sc;
    });
    int ans = 0;
    for (int i = 0; i < n; i++) if (p[i].fs.sc == 0) ans++;
    cout << ans << endl;
    for (int i = 0; i < n; i++) cout << p[i].fs.sc << ' ';
    cout << endl;
}

int32_t main() {
    cin.tie(0) -> sync_with_stdio(false);
    miku();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct