답안 #844250

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
844250 2023-09-05T11:51:14 Z vjudge1 Pod starim krovovima (COCI20_psk) C++17
8 / 50
1 ms 600 KB
#include <iostream>
#include <algorithm>
#include <utility>
using namespace std;

int main(){
    int n, liq, *ans, index, ocount;
    int64_t total;
    pair<int, int> *glasses;
    cin >> n;
    glasses = new pair<int, int>[n];
    for (int i = 0; i < n; i++){
        cin >> liq;
        total += liq;
        cin >> glasses[i].first;
        glasses[i].second = i;
    }
    std::sort(glasses, glasses + n);
    ans = new int[n];
    for (int i = 0; i < n; i++) ans[i] = 0;
    index = n - 1;
    ocount = n;
    while (total > 0){
        ocount--;
        if (glasses[index].first > total){
            ans[glasses[index].second] = total;
            total = 0;
            break;
        }
        ans[glasses[index].second] = glasses[index].first;
        total -= glasses[index].first;
        index--;
    }
    cout << ocount << endl;
    for (int i = 0; i < n; i++) cout << ans[i] << " ";
}

Compilation message

psk.cpp: In function 'int main()':
psk.cpp:26:40: warning: 'total' may be used uninitialized in this function [-Wmaybe-uninitialized]
   26 |             ans[glasses[index].second] = total;
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Integer -508 violates the range [0, 9]
2 Runtime error 0 ms 344 KB Execution killed with signal 11
3 Runtime error 1 ms 344 KB Execution killed with signal 11
4 Runtime error 1 ms 344 KB Execution killed with signal 11
5 Runtime error 1 ms 344 KB Execution killed with signal 11
6 Incorrect 0 ms 344 KB Integer -420 violates the range [0, 100]
7 Runtime error 1 ms 344 KB Execution killed with signal 11
8 Incorrect 1 ms 600 KB Output isn't correct
9 Partially correct 1 ms 344 KB Output is partially correct
10 Partially correct 1 ms 344 KB Output is partially correct