Submission #212061

# Submission time Handle Problem Language Result Execution time Memory
212061 2020-03-22T07:59:33 Z NONAME Pod starim krovovima (COCI20_psk) C++17
50 / 50
6 ms 384 KB
#include <bits/stdc++.h>

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")

#define F first
#define S second

using namespace std;


bool cmp(pair <pair <int, int>, int>  x, pair <pair <int, int>, int>  y)
{
    if (x.F.S != y.F.S) return x.F.S > y.F.S;

    if (x.F.F != y.F.F) return x.F.F > y.F.F;

    return x.S < y.S;
}
int main()
{
    //freopen("army.in","r",stdin); freopen("army.out","w",stdout);
    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n;

    cin >> n;

    vector <pair <pair <int, int>, int>  > g; g.resize(n);

    for (int i = 0; i < n; i++) {g[i].S = i; cin >> g[i].F.F >> g[i].F.S;}

    sort(g.begin(), g.end(), cmp);

    int j = 1;

    for (int i = 0; i < n; i++)
    {
        while (j < n && g[j].F.F == 0) j++;

        if (i == j) j++;

        if (j == n) break;

        if (g[i].F.S - g[i].F.F > g[j].F.F) {g[i].F.F += g[j].F.F; g[j].F.F = 0; i--; j++; continue;}

        g[j].F.F -= g[i].F.S - g[i].F.F;

        g[i].F.F = g[i].F.S;
    }

    int ans = 0;

    int anser[n];

    for (auto it : g) {if (it.F.F == 0) ans++; anser[it.S] = it.F.F;}

    cout << ans << endl;

    for (int i = 0; i < n; i++) cout << anser[i] << " ";
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct