程式考試

解題想法

此題目基本上就是 「n 次詢問」,只是多了判斷式和計算。

依照題意實作即可,可以一邊輸入一邊執行,也可以在資料全部讀完後再輸出。

範例程式

#include <bits/stdc++.h>
using namespace std;

int main() {
    int k, t, s, max_time = 0, max_score = -1, sum = 0, wrong = 0;
    cin >> k;
    for (int i = 1; i <= k; i++) {
        cin >> t >> s;
        if (s == -1) wrong++;
        else if (s > max_score){
            max_time = t;
            max_score = s;
        }
    }
    sum = max_score - k - wrong * 2;
    cout << (sum < 0 ? 0 : sum) << ' ' << max_time << '\n';
    return 0;
}