B. Hamster Farm

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Dima has a hamsters farm. Soon N hamsters will grow up on it and Dima will sell them in a city nearby.

Hamsters should be transported in boxes. If some box is not completely full, the hamsters in it are bored, that's why each box should be completely full with hamsters.

Dima can buy boxes at a factory. The factory produces boxes of K kinds, boxes of the i-th kind can contain in themselves ai hamsters. Dima can buy any amount of boxes, but he should buy boxes of only one kind to get a wholesale discount.

Of course, Dima would buy boxes in such a way that each box can be completely filled with hamsters and transported to the city. If there is no place for some hamsters, Dima will leave them on the farm.

Find out how many boxes and of which type should Dima buy to transport maximum number of hamsters.

Input

The first line contains two integers N and K (0 ≤ N ≤ 10181 ≤ K ≤ 105) — the number of hamsters that will grow up on Dima's farm and the number of types of boxes that the factory produces.

The second line contains K integers a1a2, ..., aK (1 ≤ ai ≤ 1018 for all i) — the capacities of boxes.

Output

Output two integers: the type of boxes that Dima should buy and the number of boxes of that type Dima should buy. Types of boxes are numbered from 1 to K in the order they are given in input.

If there are many correct answers, output any of them.

Examples
input
Copy
19 3
5 4 10
output
Copy
2 4
input
Copy
28 3
5 6 30
output
Copy
1 5

解题说明:此题是一道模拟题,按照题目意思找出不超过N的最大装货量,并且满足装货量为箱子型号的倍数。可以采用暴力枚举的方法进行判断,找出余数最小的情况。


#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
using namespace std;

int main() 
{
	int m, s1;
	long long n, s = 1e18, s2, x;
	scanf("%I64d%d", &n, &m);
	for (int i = 1; i <= m; i++) 
	{
		scanf("%I64d", &x);
		if (n%x < s)
		{
			s = n % x;
			s1 = i;
			s2 = n / x;
		}
	}
	printf("%d %I64d\n", s1, s2);
	return 0;
}

猜你喜欢

转载自blog.csdn.net/jj12345jj198999/article/details/79946398