1010. Discrete Function

1010. Discrete Function

Time Limit: 1.0 second
Memory Limit: 16 MB
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.

Sample

input output
3
2
6
4
1 2


水题,(可是由于数据类型的失误,竟然没有A过,还想着用库函数来着,,可是都没有64位的库,在C++中,各种long都是32位的。。)斜率最大的2点必定是相邻的2点。


#include <iostream>
#include <cmath>
using namespace std;

__int64 a[100000];

int main()
{
	int n, i, num[2];
	__int64 slope, maxSlope = 0;
	cin>>n;
	for (i=0; i<n; i++)
		cin>>a[i];
	for (i=1; i<n; i++)
	{
		slope = a[i] - a[i-1];
		if (slope < 0)
			slope = -slope;
		if (slope > maxSlope)
		{
			maxSlope = slope;
			num[0] = i-1;
			num[1] = i;
		}
	}
	cout<<num[0]+1<<" "<<num[1]+1<<endl;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值