Ural 1910. Titan ruins: hidden entrance (Titan ruins Series)

Source: Internet
Author: User

This is the first question in the Titan ruins series and will be updated later.

The principle is to find three numbers connected together to maximize the sum of them. The first number of outputs is the sum of the three numbers, the second number is the position of the middle number. It is very easy.

1 # include <iostream> 2 # include <vector> 3 using namespace STD; 4 int main () 5 {6 int N; 7 CIN> N; 8 int * A = new int [n + 1]; 9 for (INT I = 1; I <= N; ++ I) 10 CIN> A [I]; 11 int max = 0; 12 INT Index = 0; 13 for (INT I = 1; I <= n-2; ++ I) 14 {15 int sum = A [I] + A [I + 1] + A [I + 2]; 16 {17 if (sum> MAX) 18 {19 max = sum; 20 Index = I + 1; 21} 22} 23} 24 cout <max <"" <index <Endl; 25 return 0; 26}

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.