求救!!小蒟蒻wa了8个点

P2627 [USACO11OPEN] Mowing the Lawn G

HongYoung @ 2019-07-15 20:07:32

  1. include<iostream>

  2. include<cstdio>

  3. include<cstring>

  4. define ll long long

  5. using namespace std;
  6. ll n,k;ll f[100100],s[100100];
  7. ll a[100100];
  8. struct ss{
  9. ll x,y;
  10. };ss v[100100];
  11. void read(ll &x)
  12. {
  13. int t=0,r=1;
  14. char c=getchar();
  15. while(c<'0'||c>'9')(c=='-'?r=-1:0),c=getchar();
  16. while(c>='0'&&c<='9')
  17. {
  18.    t=t*10+c-'0',c=getchar();
  19. }
  20. x=t*r;return;
  21. }
  22. ll head=0,tail=1;
  23. ll getmax(ll x)
  24. {
  25. ll len=f[x-1]-s[x];
  26. while(head<=tail&&v[head].x<=len)tail--;
  27. v[++tail].x=len;v[tail].y=x;
  28. while(v[head].y<x-k&&head<=tail)head++;
  29. return v[head].x;
  30. }
  31. int main()
  32. {
  33. read(n);read(k);
  34. for(ll i=1;i<=n;i++)
  35. read(a[i]),s[i]=s[i-1]+a[i];
  36. for(int i=1;i<=n;i++)
  37. f[i]=getmax(i)+s[i];
  38. printf("%lld",f[n]);
  39. return 0;
  40. }

by EarthGiao @ 2019-07-15 20:12:54

想要更丰富的体现?使用markdown


by HongYoung @ 2019-07-15 20:34:09

@EarthGiao 我不会用,能教我怎么用吗??


|