239432026-02-02 08:10:51pirosmacska10Leghosszabb béke (75 pont)cpp17Wrong answer 19/7535ms2472 KiB
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

using ll = long long;

vector<pair<int, int>> wars;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        wars.push_back({a, b});
    }
    sort(wars.begin(), wars.end());

    
    int current_end = wars[0].second;
    int current_start = wars[0].first;
    int longest_peaceful = current_start - 1;
    int day = 1;
    for (int i = 1; i < m; i++) {
        if (wars[i].first <= current_end) {
            current_end = max(current_end, wars[i].second);
        } else {
            if (longest_peaceful < wars[i].first - current_end - 1) {
                longest_peaceful = wars[i].first - current_end - 1;
                day = current_end+1;
            }
            current_start = wars[i].first;
            current_end = wars[i].second;
        }
    }
    if (longest_peaceful < current_end - current_start + 1) {
        longest_peaceful = current_end - current_start + 1;
        day = current_start;
    }
    if(longest_peaceful) cout << longest_peaceful << " " << day << "\n";
    else cout << "-1\n";
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base19/75
1Accepted0/01ms316 KiB
2Wrong answer0/035ms2472 KiB
3Wrong answer0/31ms316 KiB
4Wrong answer0/31ms316 KiB
5Wrong answer0/31ms316 KiB
6Accepted3/31ms316 KiB
7Wrong answer0/31ms316 KiB
8Wrong answer0/41ms316 KiB
9Wrong answer0/41ms316 KiB
10Wrong answer0/41ms588 KiB
11Wrong answer0/43ms316 KiB
12Wrong answer0/43ms564 KiB
13Wrong answer0/43ms580 KiB
14Wrong answer0/43ms440 KiB
15Wrong answer0/43ms564 KiB
16Accepted4/44ms316 KiB
17Accepted4/44ms628 KiB
18Wrong answer0/44ms716 KiB
19Wrong answer0/432ms2344 KiB
20Accepted4/434ms1420 KiB
21Wrong answer0/432ms2344 KiB
22Accepted4/435ms2308 KiB