CSU 1529 Equator DP

Source: Internet
Author: User

CSU 1529 Equator DP

 

Queue optimization DP

 

Equator
Time Limit:5000 MS   Memory Limit:131072KB   64bit IO Format:% Lld & % llu

 

Submit Status

Description

 

Input

 

Output

 

Sample Input

 
3 3 1 2 3 8 4 5 -1 -1 1 -1 -1 5 2 -1 -1

Sample Output

 
6 14 0

 


 

 

/*************************************** * ******** Author: CKbossCreated Time: Tuesday, March 17, 2015 File Name: CSU1529.cpp *************************************** * *********/# include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
# Include
     
      
# Include
      
        # Include
       
         # Include
        
          # Include
         
           # Include
          Using namespace std; const int maxn = 2000200; int n, ans; int a [maxn]; int sum [maxn]; int dq [maxn], head, tail; int main () {// freopen ("in.txt", "r", stdin); // freopen ("out.txt", "w", stdout); int T_T; scanf ("% d", & T_T); while (T_T --) {scanf ("% d", & n); for (int I = 1; I <= n; I ++) {scanf ("% d", a + I); a [n + I] = a [I] ;}for (int I = 1; I <= 2 * n; I ++) sum [I] = sum [I-1] + a [I]; head = 0; tail =-1; ans = 0; for (int I = 1; I <= 2 * n; I ++) {while (head <= tail) & (sum [I]-sum [dq [tail] <0) {ans = max (ans, sum [dq [tail]-sum [dq [head]); tail --;} while (head <= tail) & (I-dq [head]> n) {ans = max (ans, sum [dq [tail]-sum [dq [head]); head ++;} dq [++ tail] = I;} printf ("% d \ n", ans);} return 0 ;}
         
        
       
      
     
    
   
  
 


 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.