# 193div2b no crossover interval and maximum

Source: Internet
Author: User
/* Question: for a certain interval, the sum of the two non-cross intervals must be the largest, and the minimum values of left_a and left_ B that meet the condition are analyzed as follows: the DP compression interval value, maintain the sum value */# include <iostream> # include <algorithm> # include <string> # include <cmath> # include <cstdio> using namespace STD; # define Manx 200009 long DP [Manx], Maxx, sum; int A [Manx]; int main () {int N, K, pos_a, pos_ B, BB; scanf ("% d", & N, & K); For (INT I = 1; I <= N; I ++) scanf ("% d ", & A [I]); For (INT I = 1; I <= K; I ++) DP [1] + = A [I]; for (INT I = k + 1; I <= N; I ++) DP [I-k + 1] = DP [I-K]-A [I-K] + A [I]; // compress for (INT I = n-2 * k + 1; I> = 1; I --) {If (Maxx <= DP [I + k]) maxx = DP [I + K], BB = I + k; // If (sum <= Maxx + dp [I]) sum = Maxx + dp [I], pos_a = I, pos_ B = BB; // requires that the two segments do not have cross intervals and the maximum} printf ("% d \ n", pos_a, pos_ B );}

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.