답안 #212062

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
212062 2020-03-22T08:01:49 Z NONAME Spiderman (COCI20_spiderman) C++17
0 / 70
124 ms 8312 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] << " ";
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 384 KB Output isn't correct
2 Incorrect 5 ms 384 KB Output isn't correct
3 Incorrect 41 ms 2808 KB Output isn't correct
4 Incorrect 124 ms 8056 KB Output isn't correct
5 Incorrect 39 ms 2936 KB Output isn't correct
6 Incorrect 111 ms 8312 KB Output isn't correct
7 Incorrect 41 ms 2936 KB Output isn't correct
8 Incorrect 42 ms 3064 KB Output isn't correct
9 Incorrect 114 ms 8312 KB Output isn't correct
10 Incorrect 116 ms 8312 KB Output isn't correct