7912022-01-16 11:26:29Halasz EszterÁruszállítás (75 pont)cpp11Runtime error 6/7578ms8172 KiB
#include <iostream>
//#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

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

vector<pair<int,int> >x;

int aa,bb,db,i,n,m,a,b;
int has(pair<int,int> a, pair<int,int> b)
{
    if (a.first>b.first) return 0;
    else return 1;
}
int leker(int a,int b,int c,int 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/03ms1964 KiB
2Runtime error0/078ms5076 KiB
3Accepted3/31ms3504 KiB
4Accepted3/31ms3504 KiB
5Runtime error0/31ms3484 KiB
6Runtime error0/31ms3492 KiB
7Runtime error0/32ms3488 KiB
8Runtime error0/41ms3504 KiB
9Runtime error0/41ms3500 KiB
10Runtime error0/41ms3516 KiB
11Runtime error0/41ms3520 KiB
12Runtime error0/41ms3528 KiB
13Runtime error0/46ms3700 KiB
14Runtime error0/47ms3832 KiB
15Runtime error0/44ms3484 KiB
16Runtime error0/47ms3700 KiB
17Runtime error0/47ms3764 KiB
18Runtime error0/48ms3884 KiB
19Runtime error0/47ms3988 KiB
20Runtime error0/48ms4148 KiB
21Runtime error0/471ms6748 KiB
22Runtime error0/475ms8172 KiB