c++ - codeforces shows WA but output is correct on terminal -
when submitted solution codeforces 551c , judge gives me wrong answer on 49th test case. when run same code on terminal (using g++4.9.2) answer comes out correct.
#include <bits/stdc++.h> #include <algorithm> #define endl '\n' using namespace std; template <class t> inline void dbg(string s,t &a) { cout << s+" => " << << endl; } int n,m; int a[100005]; bool check(long long int time) { long long int consumed,temp=0,diff; for(int i=1;n!=0 && i<=m;i++) { consumed=n; while(n>0 && consumed<time) { if(!temp) temp=a[n]; diff=temp<(time-consumed)?temp:time-consumed; temp-=diff; consumed+=diff; if(!temp) n--; } } if(n==0) return true; else return false; } int main() { cin >> n >> m; for(int i=1;i<=n;i++) cin >> a[i]; while(a[n]==0) n--; long long int last_nonempty=n,l=n+1,r=long_max,mid; while(l<r) { mid=l+(r-l)/2; n=last_nonempty; if(check(mid)) r=mid; else l=mid+1; } cout << l << endl; return 0; }
the link submission : http://codeforces.com/contest/551/submission/11582619
please help.
Comments
Post a Comment