7922022-01-16 11:36:27Halasz EszterÁruszállítás (75 pont)cpp11Runtime error 6/7576ms8216 KiB
#include <iostream>
//#include <fstream>
#include <vector>
#include <algorithm>

#define ll long long

using namespace std;

//ifstream cin("aruszallitas.in");
//ofstream cout("aruszallitas.out");

vector<pair<ll,ll> >x;

ll aa,bb,db,i,n,m,a,b;
ll has(pair<ll,ll> a, pair<ll,ll> b)
{
    if (a.first>b.first) return 0;
    else return 1;
}
ll leker(ll a,ll b,ll c,ll d)
{
    if(c<=b)
    {
        aa=min(a,c);
        bb=max(b,d);
    }
    else
    {
        db+=c-b;
        aa=-1;
        bb=-1;
    }
}
int main()
{
    cin>>n>>m;
    x.resize(m+1);
    for(i=1;i<=m;++i)
    {
        cin>>a>>b;
        x[i]={a,b};
    }
    //x.push_back({n,n});

    sort(x.begin()+1,x.end(),has);

    aa=x[1].first;
    bb=x[1].second;
    db+=x[1].first-1;
    for(i=2;i<=m;++i)
    {
        leker(aa,bb,x[i].first,x[i].second);
        if(aa==-1 && bb==-1)
        {
            aa=x[i].first;
            bb=x[i].second;

        }
    }
    db+=(n-x[m].second);
    cout<<db;

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base6/75
1Runtime error0/02ms1816 KiB
2Runtime error0/076ms6468 KiB
3Accepted3/31ms3344 KiB
4Accepted3/31ms3344 KiB
5Runtime error0/31ms3324 KiB
6Runtime error0/31ms3328 KiB
7Runtime error0/31ms3328 KiB
8Runtime error0/41ms3344 KiB
9Runtime error0/41ms3348 KiB
10Runtime error0/41ms3356 KiB
11Runtime error0/41ms3352 KiB
12Runtime error0/42ms3372 KiB
13Runtime error0/44ms3712 KiB
14Runtime error0/48ms3804 KiB
15Runtime error0/44ms3760 KiB
16Runtime error0/46ms4000 KiB
17Runtime error0/49ms4108 KiB
18Runtime error0/47ms4252 KiB
19Runtime error0/47ms4344 KiB
20Runtime error0/48ms4608 KiB
21Runtime error0/467ms8056 KiB
22Runtime error0/470ms8216 KiB