博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #464 (Div. 2) B. Hamster Farm[盒子装仓鼠/余数]
阅读量:4687 次
发布时间:2019-06-09

本文共 2163 字,大约阅读时间需要 7 分钟。

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 ≤ 1018, 1 ≤ 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 a1, a2, ..., 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
2 4
Input
Copy
28 3 5 6 30
Output
1 5

[题意]:

Dima有n 只仓鼠,有k 种盒子,每种盒子编号为1~k,可以装ai 只仓鼠,所有盒子都要装满仓鼠,剩下的仓鼠不装,Dima想让剩下的仓鼠最少,求应选盒子和盒子总数,如果有多种情况,输出任意一种。

输入格式:第一行为n和k,第二行为a1,a2,,ak

输出格式:一行,两个整数,表示应选盒子种类的编号和盒子总数。

[分析]:先找到n%a[i]的最小值,再根据最小值找pos=i+1; num=n/a[i]编号、数量.

[代码]:

#include
using namespace std;const int maxn = 1e5+10;const long long inf=1e18+50;#define ll long longint main(){ ll n,k,a[maxn],pos,num,mi; cin>>n>>k; mi=inf; for(ll i=0;i
>a[i]; mi=min(mi,n%a[i]); } for(ll i=0;i
View Code

 

转载于:https://www.cnblogs.com/Roni-i/p/8467580.html

你可能感兴趣的文章
[原创]Windows利用BitNami搭建Redmine
查看>>
Mybatis逆向工程配置文件详细介绍(转)
查看>>
Linux命令学习一日一命令(RM)
查看>>
5-1
查看>>
一名3年工作经验的程序员应该具备的技能 -- 转载
查看>>
重回博客园有感
查看>>
【转】java事件监听机制
查看>>
Leetcode 423.从英文中重建数字
查看>>
数组 Arrays类
查看>>
String类的深入学习与理解
查看>>
OLTP vs OLAP
查看>>
一些题目(3)
查看>>
Eclipse下配置主题颜色
查看>>
杂题 UVAoj 107 The Cat in the Hat
查看>>
ftp sun jdk自带
查看>>
python 元类——metaclass
查看>>
什么是缓冲,引入缓冲的原因是什么?
查看>>
叙述下列术语的定义并说明它们之间的关系:卷、块、文件、记录。
查看>>
不把DB放进容器的理由
查看>>
OnePage收集
查看>>