Find Your Solution Here

Codeforces

codeforces solution 116A – Tram

problem link–http://codeforces.com/problemset/problem/116/A

By coder_87, contest: Codeforces Beta Round #87 (Div. 2 Only), problem: (A) Tram, Accepted, #


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,a[1000],b[1000],ans,i,k,maxx=0;
    scanf("%d",&n);
    for(i=0; i<n; i++)
    {
        scanf("%d%d",&a[i],&b[i]);
    }
    k=a[0];
    for(i=0; i<n; i++)
    {
        ans=b[i]-a[i]+k;
        k=ans;
        if(ans>maxx)
            maxx=ans;
    }
    printf("%d\n",maxx);
    return 0;
}

Leave a Reply