32492023-02-23 12:11:20TuruTamasÜgyfélszolgálat (45)cpp17Runtime error 5/4567ms9968 KiB
#include <bits/stdc++.h>


using namespace std;
#define pii pair<long long, long long>

long long N, M, lines_read = 0;
queue<pii> sor;

pii next() {
    if (sor.empty()) {
        pii r;
        cin >> r.first >> r.second;
        // cout << "read to main " << r.first << " " << r.second << "\n";
        lines_read++;
        return r;
    }
    pii r = sor.front();
    sor.pop();
    return r;
}

long long count(long long ido) {
    if (lines_read == N) return sor.size();
    pii t;
    cin >> t.first >> t.second;
    // cout << "read to queue " << t.first << " " << t.second << "\n";
    sor.push(t);
    lines_read++;
    while (lines_read <= N && t.first < ido)
    {
        cin >> t.first >> t.second;
        lines_read++;
        sor.push(t);
        // cout << "read to queue " << sor.front().first << " " << sor.front().second << "\n";
    }
    return sor.size();
}

int main() {
    cin.tie(0); ios::sync_with_stdio(0);
    cin >> M >> N;
    priority_queue<pii, vector<pii>, greater<pii>> pultok;
    priority_queue<long long, vector<long long>, greater<long long>> szabad;
    vector<long long> out;
    long long max_count = 0, max_wait = 0;
    for (size_t i = 1; i < M+1; i++)
    {
        pultok.push({0, i});
    }
    for (size_t n = 0; n < N; n++)
    {
        pii pali = next();
        
        // cout << n << ": " << pali.first << " " << pali.second << "\n";
        // // cout << pultok.top().first << " " << pultok.top().second << " " << pali.first << " " << pultok.size() << endl;
        while (!pultok.empty() && pultok.top().first <= pali.first)
        {
            // if (pultok.top().first == pali.first) return 1;
            // cout << "sz: " << pultok.top().second << " " << pultok.top().first << "\n";
            szabad.push(pultok.top().second);
            pultok.pop();
            // if (pultok.top().first > pali.first) {
            //     cout << n << " " << pultok.top().first << endl; 
            //     return 1;
            // }
        }
        
        if (!szabad.empty()) {
            // cout << "pult push: " << pali.first + pali.second << " " << szabad.top() << "\n";
            out.push_back(szabad.top());
            pultok.push({pali.first + pali.second, szabad.top()});
            szabad.pop();
        }
        else {
            cout << n << endl;
            return 1;
            long long elso = pultok.top().first;
            max_wait = max(max_wait, elso-pali.first);
            max_count = max(max_count, count(elso));
            // cout << "nincs sz\n";
            while (pultok.top().first == elso && !pultok.empty()) 
            {
                // cout << "\tsz push: " << pultok.top().second << " " << pultok.top().first << "\n";
                szabad.push(pultok.top().second);
                pultok.pop();
            }
            // cout << "pultok push: " << elso + pali.second << " " << szabad.top() << "\n";
            pultok.push({elso + pali.second, szabad.top()});
            out.push_back(szabad.top());
            szabad.pop();
        }
    }
    while (pultok.size() > 1) pultok.pop();
    cout << pultok.top().first << " " << max_wait << " " << max_count << "\n"; 
    // for (long long x : out) cout << x << "\n";
}
SubtaskSumTestVerdictTimeMemory
base5/45
1Runtime error0/03ms1828 KiB
2Runtime error0/07ms2928 KiB
3Partially correct1/23ms2336 KiB
4Runtime error0/23ms2548 KiB
5Runtime error0/23ms2752 KiB
6Runtime error0/23ms2888 KiB
7Runtime error0/23ms3240 KiB
8Runtime error0/248ms9096 KiB
9Runtime error0/224ms7364 KiB
10Runtime error0/250ms9048 KiB
11Runtime error0/245ms9324 KiB
12Runtime error0/243ms9288 KiB
13Runtime error0/224ms7604 KiB
14Runtime error0/246ms9292 KiB
15Runtime error0/225ms7860 KiB
16Runtime error0/224ms7820 KiB
17Runtime error0/225ms7816 KiB
18Runtime error0/225ms7816 KiB
19Partially correct1/267ms9756 KiB
20Partially correct1/367ms9712 KiB
21Runtime error0/450ms9968 KiB
22Partially correct2/461ms9924 KiB