总时间限制:
1000ms
内存限制:
65536kB
描述
Given the predictive stock prices P of N days. Find two days I and J to buy and sell the stock. I is less than J and (P[J] minus P[I]) should be maximum.
输入
First line: one positive integers N (N <= 100).
Second line: N positive integers P[i] (P[i] <= 1000).
输出
Two integers I and J.
样例输入
5 3 5 4 6 2
样例输出
1 4
#include <bits/stdc++.h>//Writed by Wangzhimin Date:2022.06.01
using namespace std;
int n,a[105];
int main()
{
int i,j,x,y,max=-1;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
if(a[j]-a[i]>max)
{
max=a[j]-a[i];
x=i;
y=j;
}
cout<<x+1<<" "<<y+1;
return 0;
}