11681209
http://codeforces.net/problemset/problem/538/C
i have been stuck in this problem for like 2 days and i can't move to another one . i am so close . testcase wrong answer . wrong answer 1st words differ — expected: '219', found: '218' so annoying . :D
here is my code i hope you can help
include <bits/stdc++.h>
using namespace std;
int totaltime,n; pair < int , int > arr[100005];
int main() { scanf("%d %d",&totaltime,&n);
for(int i=1; i<=n; i++) { cin>>arr[i].first; cin>>arr[i].second; } arr[0].first=arr[0].second=0; int ans=0; for(int i=1; i<=n; i++) { // cout<<ans<<endl; if( abs(arr[i].second-arr[i-1].second) > abs(arr[i].first-arr[i-1].first)&&i!=1) { // cout<<i<<endl; cout<<"IMPOSSIBLE\n"; return 0; } else { //if((abs(arr[i].first-arr[i-1].first)%2==0))ans= max (ans, ((abs(arr[i].first-arr[i-1].first) - abs(arr[i].second-arr[i-1].second))/2) + arr[i-1].second ); ans= max (ans, ((abs(arr[i].first-arr[i-1].first) - abs(arr[i].second-arr[i-1].second))/2) + arr[i-1].second ); } }
// cout<<ans<<endl; ans=max(ans,arr[n].second+totaltime-arr[n].first); cout<<ans<<endl;
return 0;
}
This my code — http://codeforces.net/contest/538/submission/10911246 — it's Accepted.