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)