2-2-Maximum difference between the left and right values

Source: Internet
Author: User

Title Description:
Given an integer array of length N (n>1), a can be divided into two parts, left part A[0..K],
The right portion of the a[k+1..n-1],k can be evaluated in the range [0,n-2].
In so many partitioning schemes, the largest value in the left part minus the absolute value of the right part maximum, what is the maximum?
Given the integer array A and the size of the group N, return the answer to the question you asked.
Test examples:
[2,7,3,1,1],5
Returns: 6

1#include <iostream>2#include <vector>3 using namespacestd;4 5 intFindmaxgap (vector<int> A,intN) {6     intmax = a[0];7      for(inti =0; I < n; i++)8         if(A[i] >max)9Max =A[i];Ten     intMinux = a[0] > a[n-1] ? a[n-1]: a[0]; One     returnMax-Minux; A } -  - intMain () { thevector<int>A; -A.push_back (2); -A.push_back (7); -A.push_back (3); +A.push_back (4); -A.push_back (1); +A.push_back (1); A     //A.push_back (1); at     //A.push_back (2); -     //A.push_back (3); -     //A.push_back (3); -     //A.push_back (8); -     //A.push_back (9); -cout << Findmaxgap (A,6) <<Endl; in     return 0; -}

2-2-Maximum difference between the left and right values

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.