Sdut 3033 This question really does not know what name is good (thinking skillfully method)

Source: Internet
Author: User

Well, I don't know what it's called. Time limit:1000ms Memory limit:65536k have questions? Dot here ^_^ Topic description Lazy Think background story, straight to the point. There is an integer sequence of length n a0,a1,a2 .... An-1. Find two integers ai and aj,ai in front of AJ, i.e. I<j, making ai-aj as large as possible. Please output the value of the maximum possible ai-aj. Inputmultiple sets of inputs. The first line of each set of test data is an integer n, then the second row is n integers, number iRepresents an AI. (Number of test data groups <=20,2<=n<=10^6,-10^8<=ai<=10^8). Outputs one integer for each set of test data output, which is the maximum possible Ai-aj value. Sample input
53 1 2 4 353 1 2 4 1
Sample output
23

#include <iostream> #include <string> #include <stdio.h> #include <algorithm>using namespace Std;int MAX (int a, int b) {    return a>b?a:b;} int main () {    int n;    int max, MM;    int I, J;    int DD, FF;    while (scanf ("%d", &n)!=eof)    {        scanf ("%d", &dd);        scanf ("%d", &ff);        Max=max (DD, FF);        MM=DD-FF;        for (i=2; i<n; i++)        {            scanf ("%d", &dd);            if (Dd<=max)//The maximum value of the current segment            {                if ((MAX-DD) >mm)                    mm=max-dd;            }            else            {                if ((MAX-DD) >mm)                  mm=max-dd;                MAX=DD; Update the maximum value of the current segment            }        }        cout<<mm<<endl;    }    return 0;}

Sdut 3033 This question really does not know what name is good (thinking skillfully method)

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.