545C codeforces - Woodcutters


545C codeforces - Woodcutters









Solution in C++


#include <bits/stdc++.h>
using namespace std;

typedef long long int lli;
#define pii pair<int,int>

lli n,t1,t2,sol=2,las;
vector<pair<int,int> > all;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n;
    all.resize(n);
    for(int i=0;i<n;i++)
    {
        cin>>t1>>t2;
        all[i]={t1,t2};
    }
    for(int i=1;i<n-1;i++)
    {
        if(all[i].first-all[i].second>all[i-1].first+las)sol++;
        else if(all[i].first+all[i].second<all[i+1].first){sol++;all[i].first+=all[i].second;}
    }
    cout<<((n==1)?1:sol);
    return 0;
}

Share on Google Plus

About Mohamed Sobhi

My name is Mo.Sobhy ,I study at School excelling high school in Ain Shams ,Cairo
My hobbies is programming ,and web development ,playing chess and writing horror stories.
    Blogger Comment
    Facebook Comment

0 التعليقات:

إرسال تعليق