Codeforces Round #464 (Div. 2) B. Hamster Farm
B. Hamster Farm
time limit per test2 seconds
memory limit per test256 megabytes
Problem Description
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 ≤ 10e18, 1 ≤ K ≤ 10e5) — 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 ≤ 10e18 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
19 3
5 4 10
output
2 4
input
28 3
5 6 30
output
1 5
解题心得:
- 题意是一个农夫有n只仓鼠,k中笼子,每种笼子可以装Ki只仓鼠,只有笼子装满才能将仓鼠带走,选择一种笼子,要使带走的仓鼠最多,问最少要多少个笼子。
- 暴力,每次mod一下找最小值。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+100;
ll k[maxn],sum,K;
int main(){
scanf("%lld%lld",&sum,&K);
ll ans_pos = -1,Min = 1e18;
for(int i=1;i<=K;i++){
scanf("%lld",&k[i]);
ll temp = sum%k[i];
if(temp < Min){
Min = temp;
ans_pos = i;
}
}
printf("%lld %lld",ans_pos,sum/k[ans_pos]);
return 0;
}
Codeforces Round #464 (Div. 2) B. Hamster Farm的更多相关文章
- Codeforces Round #464 (Div. 2) B. Hamster Farm[盒子装仓鼠/余数]
B. Hamster Farm time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #464 (Div. 2)
A. Love Triangle time limit per test: 1 second memory limit per test: 256 megabytes input: standard ...
- Codeforces Round #464 (Div. 2) E. Maximize!
题目链接:http://codeforces.com/contest/939/problem/E E. Maximize! time limit per test3 seconds memory li ...
- Codeforces Round #464 (Div. 2) D. Love Rescue
D. Love Rescue time limit per test2 seconds memory limit per test256 megabytes Problem Description V ...
- Codeforces Round #464 (Div. 2) C. Convenient For Everybody
C. Convenient For Everybody time limit per test2 seconds memory limit per test256 megabytes Problem ...
- Codeforces Round #464 (Div. 2) A Determined Cleanup
A. Love Triangle time limit per test1 second memory limit per test256 megabytes Problem Description ...
- Codeforces Round #464 (Div. 2) A. Love Triangle[判断是否存在三角恋]
A. Love Triangle time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #464 (Div. 2) D题【最小生成树】
Valya and Tolya are an ideal pair, but they quarrel sometimes. Recently, Valya took offense at her b ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
随机推荐
- C 碎片十 关键字&库函数
一.关键字 1, sizeof sizeof关键字用于计算所占空间大小的 格式:sizeof(类型名/变量名); 2, typedef typedef关键字用于重命名数据类型的,相当于给原来的数据类型 ...
- IDEA/AS快捷键收集&习惯
1.Alt+Enter单包引入 2.Ctrl+O (在类中)快速重写父类方法 3.Ctrl+F12显示类结构 4.代码提示 -Ctrl+Alt+空格 代码提示 -Ctrl+Shift+回车 在末尾自动 ...
- hibernate课程 初探单表映射3-3 对象类型
本节简介: 1 简介对象类型(重点是音视频blob类型) 2 demo(对图片的写入数据库与读取) 1 简介对象类型 映射类型 java类型 标准sql类型 mysql类型 oracle类型 bina ...
- Java正则表达式—小应用—简易爬虫
在上一篇中,学习了正则表达式的四个功能.即匹配.分割.替换.获取. 利用获取功能,可以实现简单的网页爬虫. 4,获取:将字符串中的符合规则的子串取出. 获取功能的操作步骤: 1,将正则表达式 ...
- mysql数据库字段类型的选择原则
原文链接:http://blog.csdn.net/u013412790/article/details/51615407 数据库类型的选择对数据库的性能影响很大 1 . 数据类型会影响存储空间的开销 ...
- cocos2d-x-2.2.0_win7+vs2010搭建_eclipse+ndk-r9+cygwin搭建_教程以及编译问题汇总
声明:我是才用c/c++和cocos2d-x的如果有错误欢迎指出 文章内容我亲测过可以通过,同时我也会一直更新内容 感谢那些把自己的东西分享出来的人 原文地址:http://www.cnblogs.c ...
- X86/X64 函数调用约定
C 语言有 __cdecl.__stdcall.__fastcall.naked.__pascal. C++ 语言有 __cdecl.__stdcall.__fastcall.naked.__pasc ...
- Angular4中常用管道
通常我们需要使用管道实现对数据的格式化,Angular4中的管道和之前有了一些变化,下面说一些常用的管道. 一.大小写转换管道 uppercase将字符串转换为大写 lowercase将字符串转换为小 ...
- python_69_内置函数1
#abs()取绝对值 ''' all(iterable) Return True if all elements of the iterable are true (or if the iterabl ...
- Python判断一个数是否为小数
一.判断一个数是否为小数 1.有且仅有一个小数点 2.小数点的左边可能为正数或负数 3.小数点的右边为正数 二.实现代码 def is_float(str): if str.count('.') == ...