codeforces显示WA但终端输出正确

时间:2015-06-14 16:36:39

标签: c++

当我提交代码强制551C的解决方案时,法官在第49次测试案例中给出了错误的答案。但是当我在终端上运行相同的代码时(使用g ++ 4.9.2),答案是正确的。

#include <bits/stdc++.h>
#include <algorithm>
#define endl '\n'
using namespace std;

template <class T>
inline void dbg(string s,T &a)
{
      cout << s+" is => " << a << 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;
}

我提交的链接是:http://codeforces.com/contest/551/submission/11582619

请帮忙。

0 个答案:

没有答案