답안 #543952

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
543952 2022-03-31T17:05:41 Z AlperenT Pod starim krovovima (COCI20_psk) C++17
50 / 50
3 ms 356 KB
#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] << " ";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 3 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 3 ms 356 KB Output is correct