36422023-03-01 14:40:35Erik_GepardÁruszállítás üres szakaszaicpp17Wrong answer 2/5035ms5708 KiB
#include <bits/stdc++.h>
using namespace std;


void solve(){
    int n, m;
    cin>>n>>m;
    vector<pair<int,int>> a(m);
    for(int i=0; i<m; i++){
        cin>>a[i].first>>a[i].second;
    }
    sort(a.begin(), a.end());
    int covered=a[0].second, ans=a[0].first-1;
    for(int i=1; i<m; i++){
        if(a[i].first>covered){
            ans+=a[i].first-covered;
        }
        covered=max(a[i].second, covered);
    }
    if(n>covered){
        ans+=n-covered;
    }
    cout<<ans<<"\n";
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base2/50
1Wrong answer0/03ms1824 KiB
2Wrong answer0/035ms3520 KiB
3Wrong answer0/23ms2344 KiB
4Accepted2/23ms2444 KiB
5Wrong answer0/23ms2528 KiB
6Wrong answer0/23ms2652 KiB
7Wrong answer0/23ms2888 KiB
8Wrong answer0/23ms2988 KiB
9Wrong answer0/23ms2992 KiB
10Wrong answer0/23ms3064 KiB
11Wrong answer0/23ms3152 KiB
12Wrong answer0/23ms3160 KiB
13Wrong answer0/34ms3560 KiB
14Wrong answer0/34ms3684 KiB
15Wrong answer0/34ms3880 KiB
16Wrong answer0/327ms5120 KiB
17Wrong answer0/327ms5208 KiB
18Wrong answer0/332ms5236 KiB
19Wrong answer0/34ms3968 KiB
20Wrong answer0/34ms4232 KiB
21Wrong answer0/332ms5432 KiB
22Wrong answer0/332ms5708 KiB