codeforces1197D Yet Another Subarray Problem dp

URL: http://codeforces.com/problemset/problem/1197/D

Meaning of the questions:

It gives the length of the sequence and $ n-$ $ m $, $ k $ ($ n \ leq 3e5, m \ leq 10, k \ leq 1e9 $), seeking $ \ sum_ {i = l} ^ {r} a_i -k \ lceil \ frac {r-l + 1} {m} \ rceil $ maximum.

answer:

The first thing to go is the greatest feeling and sub-columns, and then directly WA at t3 and t8. Feel no problem, in fact, not think about it later, because minus the length of the interval, with the change in length of the sub-columns, even if the recording interval length selected online process. Period not lost after subtracting the corresponding values ​​may lose less than the. So the question for each number can only enumerate its position, that is, $ j% m == i? (I \ in [0, m-1]) $, and let right at the point (to meet the $ j% m == I $) subtracting the value K $ a $, to form a new sequence, find the maximum in the new sub-sequence, and column. Be sure to update when reaching the maximum at the right point to solve, otherwise it will leak minus a $ k $. Why do I need to do? The answer must be found in the right end of a particular enumeration, enumeration like this can be discussed on the minus k corresponding number in the classification to be unnecessary, or they may be greater than the length of the interval a $ m $ interval occurs only minus one $ k $ of erroneous results.

AC Code:

#include <bits / STDC ++ H.> 
the using namespace STD; 
Long Long A [300005], B [300005]; 
int main () 
{ 
    int n-, m, K; 
    CIN >> >> m >> n-K; 
    for ( 0 = I int; I <n-; I ++) 
        CIN >> A [I]; 
    Long Long Maxx = 0, ANS = 0; 
    for (int I = 0; I <m; I ++) // enumeration Save position k 
    { 
        for (int J = 0; J <n-; J ++) 
            B [J] = a [J] - (? J == I k% m: 0); // Save k is the need for local processing 
        Maxx = 0; 
        for (int J = 0; J <n-; J ++) 
        { 
            Maxx = max (Maxx + B [J], 0LL); // do the most sub-column and 
            if (j% m == I) 
                ANS = max (ANS, Maxx); // ensures that all sub-columns and the maximum k is decremented by the corresponding number 
            cout << maxx << "";
        }
        cout<<endl;
    }
    cout<<ans<<endl;
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/Aya-Uchida/p/11298594.html