7902022-01-16 11:22:45Halasz EszterÁruszállítás (75 pont)cpp11Runtime error 0/75114ms63492 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+1;++i)
    {
        leker(aa,bb,x[i].first,x[i].second);
        if(aa==-1 && bb==-1)
        {
            aa=x[i].first;
            bb=x[i].second;

        }
    }
    cout<<db;

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/75
1Runtime error0/050ms61924 KiB
2Runtime error0/0114ms61928 KiB
3Runtime error0/334ms63400 KiB
4Runtime error0/332ms63416 KiB
5Runtime error0/335ms63420 KiB
6Runtime error0/348ms63424 KiB
7Runtime error0/335ms63428 KiB
8Runtime error0/445ms63432 KiB
9Runtime error0/435ms63436 KiB
10Runtime error0/435ms63436 KiB
11Runtime error0/441ms63440 KiB
12Runtime error0/437ms63464 KiB
13Runtime error0/437ms63316 KiB
14Runtime error0/439ms63488 KiB
15Runtime error0/435ms63328 KiB
16Runtime error0/437ms63488 KiB
17Runtime error0/441ms63492 KiB
18Runtime error0/437ms63400 KiB
19Runtime error0/437ms63492 KiB
20Runtime error0/452ms63424 KiB
21Runtime error0/4103ms62792 KiB
22Runtime error0/4104ms62760 KiB