B. Hamster Farm

5人阅读 评论(0) 收藏 举报
分类:

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;
}

查看评论

Codeforces Round #464 (Div. 2) B. Hamster Farm

B. Hamster FarmDima has a hamsters farm. Soon N hamsters will grow up on it and Dima will sell them ...
  • s540239976
  • s540239976
  • 2018-02-18 12:28:34
  • 213

cf 464 B. Hamster Farm

B. Hamster Farmtime limit per test2 secondsmemory limit per test256 megabytesinputstandard i...
  • PragIncor
  • PragIncor
  • 2018-02-18 13:14:42
  • 121

Codeforces Round #464 (Div. 2) B. Hamster Farm 水题

B. Hamster Farmtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutp...
  • Frost_Bite
  • Frost_Bite
  • 2018-02-19 22:42:36
  • 38

939B. Hamster Farm

Dima has a hamsters farm. Soon N hamsters will grow up on it and Dima will sell them in a city nearb...
  • islittlehappy
  • islittlehappy
  • 2018-02-18 09:14:03
  • 192

Codeforces Round #464 (Div. 2)B. Hamster Farm

#include &amp;lt;bits/stdc++.h&amp;gt; using namespace std; long long a[1000005]; int main() { l...
  • qq_37252519
  • qq_37252519
  • 2018-02-18 13:38:34
  • 30

Codeforces 939B(Hamster Farm)

这道题目很明显的就是一道翻译题 很简单没有坑 这里就不详细解释了,详解请看代码。题目:Dima has a hamsters farm. Soon N hamsters will grow up on...
  • Puppet__
  • Puppet__
  • 2018-02-21 22:35:42
  • 23

利用arpspoof、tcpdump、ferret及hamster劫持登录会话

利用arpspoof、tcpdump、ferret及hamster劫持登录会话
  • u011843461
  • u011843461
  • 2015-01-25 22:59:32
  • 4106

hamster

March 11th, 2010  Key word: hamster,difficult         I saw hamster on LJ, I remember some spring ag...
  • Cecil1119
  • Cecil1119
  • 2010-03-14 15:56:00
  • 217

HDU_1198_FarmIrrigation

Farm Irrigation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)...
  • baidu_29410909
  • baidu_29410909
  • 2015-08-11 16:02:42
  • 301

POJ_2135_Farm Tour(最小费用流)

题意:给你一副无向图,问从1->n->1这样走一个来回所用的最短路径是多少,每条边只能走一次。 分析:最小费用流问题。把边的长度当成费用,每条边容量为1,由于是无向图,所以每条边要处理两次,即u->...
  • jhgkjhg_ugtdk77
  • jhgkjhg_ugtdk77
  • 2015-09-11 11:48:05
  • 605
    个人资料
    持之以恒
    等级:
    访问量: 220万+
    积分: 3万+
    排名: 122
    文章存档
    最新评论