제출 #1336497

#제출 시각아이디문제언어결과실행 시간메모리
1336497mamabearData Centers (EGOI22_datacenters)C++20
100 / 100
260 ms1988 KiB
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

    int n, s;
    if (!(cin >> n >> s)) return 0;

    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    sort(a.begin(), a.end(), greater<int>());

    vector<int> temp(n);

    for (int i = 0; i < s; i++) {
        int m, c;
        cin >> m >> c;

        for (int j = 0; j < c; j++) {
            a[j] -= m;
        }

        int p1 = 0;
        int p2 = c;
        int p_temp = 0;

        while (p1 < c && p2 < n) {
            if (a[p1] >= a[p2]) {
                temp[p_temp++] = a[p1++];
            } else {
                temp[p_temp++] = a[p2++];
            }
        }

        while (p1 < c) {
            temp[p_temp++] = a[p1++];
        }

        while (p2 < n) {
            temp[p_temp++] = a[p2++];
        }

        a.swap(temp);
    }

    for (int i = 0; i < n; i++) {
        cout << a[i] << (i == n - 1 ? "" : " ");
    }
    cout << "\n";

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...