Discrete Function(简单数学题)

时间:2021-03-12 17:19:21

Discrete Function

There is a discrete function. It is specified for integer arguments from 1 to N (2 ≤ N ≤ 100000). Each value of the function is longint (signed long in C++). You have to find such two points of the function for which all points between them are below than straight line connecting them and inclination of this straight line is the largest.

Input

There is an N in the first line. Than N lines follow with the values of the function for the arguments 1, 2, …, N respectively.

Output

A pair of integers, which are abscissas of the desired points, should be written into one line of output. The first number must be less then the second one. If it is any ambiguity your program should write the pair with the smallest first number.

Example

input output
3
2
6
4
1 2

//简单数学题,题意是,在一个横坐标是 1 - N 的整数的坐标里,每个整数代表纵坐,若任意两个点都可连成一条直线,问倾角最大的两个点横坐标是?

//容易想到,必须是两个相邻的点才有可能倾角最大,所以一重循环就解决了

 #include<stdio.h>
#include<math.h>
double a[];
int main()
{
int n; scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%lf",&a[i]); int s=,e=;
double ans=-;
for(int i=;i<=n;i++)
{
double tmp=fabs(a[i]-a[i-]);
if(ans<tmp)
{
s=i-;
e=i;
ans=tmp;
}
}
printf("%d %d\n",s,e);
return ;
}