• 题意:
  • 给出n个数,让你输出这n个数的最大连续子序列 的左端点和右端点和最大值
  • 输入:
  • 5
  • -1 2 3 -4 9
  • 输出:
  • max= 10,L= 2,R= 5
  • 代码:
    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
      int m,l,r,start,maxx;
      int dp[100010];
      scanf("%d",&m);
      for(int i = 1;i <= m;i++)
          scanf("%d",&dp[i]);
      l = r = start = 1;
      maxx = dp[1];
      for(int i = 2;i <= m;i++)
      {
          if(dp[i-1] >= 0)
              dp[i] = dp[i-1] + dp[i];
          else
              start = i;
          if(dp[i] > maxx){
              maxx = dp[i];
              l = start;
              r = i;
          }
      }
      cout<<"max= "<<maxx<<",L= "<<l<<",R= "<<r<<endl;
      return 0;
    }
    

```