Submission #844239

# Submission time Handle Problem Language Result Execution time Memory
844239 2023-09-05T11:44:25 Z vjudge1 Pod starim krovovima (COCI20_psk) C++17
50 / 50
1 ms 600 KB
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int int64_t
#define ordered_set                              \
    tree<int, null_type, less<int>, rb_tree_tag, \
         tree_order_statistics_node_update>
#define F first
#define S second
#define I insert
#define PB push_back
#define POB pop_back
#define sqr(a) ((a) * (a))
#define P pop
#define max3(a, b, c) (max(a, max(b, c)))
#define max4(a, b, c, d) (max(max(a, b), max(c, d)))
#define min3(a, b, c) (min(a, min(b, c)))
#define min4(a, b, c, d) (min(min(a, b), min(c, d)))
#define MOD 1000000007
#define mod 998244353
int binpow(int a, int p, int m = MOD) {
    int ans = 1;
    while (p) {
        if (p & 1) ans = ((ans % m) * (a % m)) % m;
        a = sqr(a) % m;
        p >>= 1;
    }
    return ans;
}
void solve() {
    int n;
    cin >> n;
    vector<pair<int, int>> z(n, {0, 0});
    int liqu = 0;
    for (int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp >> z[i].F;
        liqu += tmp;
        z[i].S = i;
    }
    sort(z.rbegin(), z.rend());
    vector<pair<int, int>> ans(n, {0, 0});
    int ansi = 0;
    for (int i = 0; i < n; i++) {
        ans[i].F = z[i].S;
        ans[i].S = min(z[i].F, liqu);
        liqu -= ans[i].S;
        if (ans[i].S == 0) ansi++;
    }
    sort(ans.begin(), ans.end());
    cout << ansi << endl;
    for (int i = 0; i < n; i++) {
        cout << ans[i].S;
        if (i != n - 1) cout << ' ';
    }
}
int32_t main() {
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 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 344 KB Output is correct
10 Correct 1 ms 600 KB Output is correct