답안 #440503

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
440503 2021-07-02T10:48:33 Z colossal_pepe Pod starim krovovima (COCI20_psk) C++17
40 / 50
1 ms 240 KB
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

struct Glass {
    int index, vol, cap;
};

int n, t, z, liquid = 0;
vector<Glass> glasses;

int main() {
    cin >> n;
    glasses.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> t >> z;
        liquid += t;
        glasses[i].index = i, glasses[i].vol = t, glasses[i].cap = z;
    }
    if (liquid > 0) {
        sort(glasses.begin(), glasses.end(),
             [](Glass g1, Glass g2) { return g1.cap > g2.cap; });
        bool said = 0;
        for (int i = 0; i < n; i++) {
            int pour = min(glasses[i].cap, liquid);
            glasses[i].vol = pour;
            liquid -= pour;
            if (liquid <= 0 and not said) {
                cout << n - i - 1 << endl;
                said = 1;
            }
        }
        sort(glasses.begin(), glasses.end(),
             [](Glass g1, Glass g2) { return g1.index < g2.index; });
    } else {
        cout << n << endl;
    }
    for (Glass g : glasses) {
        cout << g.vol << ' ';
    }
    cout << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Incorrect 1 ms 204 KB Output isn't correct
10 Incorrect 1 ms 240 KB Output isn't correct