Cod sursa(job #2929786)

Utilizator AleXutzZuDavid Alex Robert AleXutzZu Data 26 octombrie 2022 20:48:11
Problema Orase Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.88 kb
#include <iostream>
#include <fstream>

#define MAX_SIZE 1000001
int street[MAX_SIZE] = {0};

int main() {
    std::ifstream input("orase.in");
    std::ofstream output("orase.out");

    int n, m;
    input >> m >> n;

    unsigned long long ans = 0;
    for (int i = 0; i < n; ++i) {
        int d, l;
        input >> d >> l;
        if (street[d] == 0) street[d] = l;
        else {
            ans = std::max<unsigned long long>(ans, l + street[d]);
            street[d] = std::max(l, street[d]);
        }
    }


    for (int i = 0; i <= m; ++i) {
        if (street[i]) {
            unsigned long long sum = street[i];
            int j = i;
            while (j < m && street[j + 1] == 0) j++, sum++;
            if (j + 1 > m) sum = 0;
            else sum += street[j + 1] + 1;
            ans = std::max(ans, sum);
            i = j;
        }
    }
    output << ans;
    return 0;
}