제출 #543952

#제출 시각아이디문제언어결과실행 시간메모리
543952AlperenTPod starim krovovima (COCI20_psk)C++17
50 / 50
3 ms356 KiB
#include <bits/stdc++.h>

using namespace std;

const int N = 1000 + 5;

int n, ans[N];

struct Item{
    int cur, total, i;

    bool operator < (const Item &sc) const{
        return array<int, 3>{total, cur, i} < array<int, 3>{sc.total, sc.cur, sc.i};
    }
};

Item arr[N];

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);

    cin >> n;

    for(int i = 1; i <= n; i++){
        cin >> arr[i].cur >> arr[i].total;

        arr[i].i = i;
    }

    sort(arr + 1, arr + n + 1);

    for(int i = 1; i <= n; i++){
        for(int j = i + 1; j <= n; j++){
            int tmp = min(arr[i].cur, arr[j].total - arr[j].cur);

            arr[i].cur -= tmp, arr[j].cur += tmp;
        }
    }

    for(int i = 1; i <= n; i++) ans[arr[i].i] = arr[i].cur;

    cout << count(ans + 1, ans + n + 1, 0) << "\n";

    for(int i = 1; i <= n; i++) cout << ans[i] << " ";
}
#Verdict Execution timeMemoryGrader output
Fetching results...