D1. Magic Powder - 1
time limit per test:

1 second

memory limit per test:

256 megabytes

input:

standard input

output:

standard output

This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single solution to the both versions. If you find the problem too difficult in large constraints, you can write solution to the simplified version only.

Waking up in the morning, Apollinaria decided to bake cookies. To bake one cookie, she needs n ingredients, and for each ingredient she knows the value ai — how many grams of this ingredient one needs to bake a cookie. To prepare one cookie Apollinaria needs to use all n ingredients.

Apollinaria has bi gram of the i-th ingredient. Also she has k grams of a magic powder. Each gram of magic powder can be turned to exactly 1 gram of any of the n ingredients and can be used for baking cookies.

Your task is to determine the maximum number of cookies, which Apollinaria is able to bake using the ingredients that she has and the magic powder.

Input

The first line of the input contains two positive integers n and k (1 ≤ n, k ≤ 1000) — the number of ingredients and the number of grams of the magic powder.

The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ 1000), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie.

The third line contains the sequence b1, b2, ..., bn (1 ≤ bi ≤ 1000), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has.

Output

Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder.

Examples
input
3 1
2 1 4
11 3 16
output
4
input
4 3
4 3 5 6
11 12 14 20
output
3
Note

In the first sample it is profitably for Apollinaria to make the existing 1 gram of her magic powder to ingredient with the index 2, then Apollinaria will be able to bake 4 cookies.

In the second sample Apollinaria should turn 1 gram of magic powder to ingredient with the index 1 and 1 gram of magic powder to ingredient with the index 3. Then Apollinaria will be able to bake 3 cookies. The remaining 1 gram of the magic powder can be left, because it can't be used to increase the answer.

题目链接:http://codeforces.com/problemset/problem/670/D1


题意:做一个饼干需要有n种材料,每种材料需要ai克。现在每种材料有bi克。还有k克神奇材料,可以代替那n种材料。1克神奇材料替换1克普通材料。

思路:按num[i]=bi/ai升序。暴力求出num[i]时需要得神奇材料。
 
代码:
for循环直接暴力:
#include<bits/stdc++.h>
using namespace std;
struct ingredient
{
int a,b,num,sign;
} gg[];
int add[];
int cmp(ingredient x,ingredient y)
{
if(x.num!=y.num) return x.num<y.num;
else return x.sign<y.sign;
}
int main()
{
int i,j,n,k;
scanf("%d%d",&n,&k);
for(i=; i<=n; i++)
scanf("%d",&gg[i].a);
for(i=; i<=n; i++)
{
scanf("%d",&gg[i].b);
gg[i].num=gg[i].b/gg[i].a;
gg[i].sign=gg[i].b%gg[i].a;
}
sort(gg+,gg+n+,cmp);
gg[n+].num=gg[n].num+;
gg[n+].sign=;
int sum=,flag=;
add[]=;
for(i=; i<=n; i++)
{
sum+=gg[i].a;
flag+=gg[i].sign;
if(gg[i].num<gg[i+].num)
{
add[i]=add[i-]+sum*(gg[i+].num-gg[i].num)-flag;
if(add[i]>=k)
{
k-=add[i-];
cout<<gg[i].num+(k+flag)/sum<<endl;
break;
}
flag=;
}
else add[i]=add[i-];
}
if(i>n)
{
k-=add[n];
cout<<gg[n+].num+k/sum;
}
return ;
}

每次增加num就进行sort排序:

#include<bits/stdc++.h>
using namespace std;
int a[],b;
struct ingredient
{
int a,b,num;
} gg[];
int cmp(ingredient x,ingredient y)
{
return x.num<y.num;
}
int main()
{
int i,n,k;
scanf("%d%d",&n,&k);
for(i=; i<n; i++)
scanf("%d",&gg[i].a);
for(i=; i<n; i++)
{
scanf("%d",&gg[i].b);
gg[i].num=gg[i].b/gg[i].a;
}
sort(gg,gg+n,cmp);
while(k>)
{
int sign=(gg[].num+)*gg[].a;
if((sign-gg[].b)<=k)
{
k-=(sign-gg[].b);
gg[].b=sign;
gg[].num++;
}
else
{
gg[].b+=k;
k=;
}
sort(gg,gg+n,cmp);
}
cout<<gg[].num<<endl;
return ;
}

Codeforces 670D1. Magic Powder - 1 暴力的更多相关文章

  1. CodeForces 670D2 Magic Powder 二分

    D2. Magic Powder - 2 The term of this problem is the same as the previous one, the only exception — ...

  2. Codeforces 632F - Magic Matrix(暴力 bitset or Prim 求最小生成树+最小瓶颈路)

    题面传送门 开始挖老祖宗(ycx)留下来的东西.jpg 本来想水一道紫题作为 AC 的第 500 道紫题的,结果发现点开了道神题. 首先先讲一个我想出来的暴力做法.条件一和条件二直接扫一遍判断掉.先将 ...

  3. CodeForces 670D Magic Powder

    二分. 二分一下答案,然后验证一下. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cst ...

  4. CodeForces 670D2 Magic Powder - 2 (二分)

    题意:今天我们要来造房子.造这个房子需要n种原料,每造一个房子需要第i种原料ai个.现在你有第i种原料bi个.此外,你还有一种特殊的原料k个, 每个特殊原料可以当作任意一个其它原料使用.那么问题来了, ...

  5. CodeForces 670D1 暴力或二分

    今天,开博客,,,激动,第一次啊 嗯,,先来发水题纪念一下 D1. Magic Powder - 1   This problem is given in two versions that diff ...

  6. Codeforces Round #350 (Div. 2) D1. Magic Powder - 1 二分

    D1. Magic Powder - 1 题目连接: http://www.codeforces.com/contest/670/problem/D1 Description This problem ...

  7. Codeforces Round #350 (Div. 2)_D2 - Magic Powder - 2

    D2. Magic Powder - 2 time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. codeforces 350 div2 D Magic Powder - 2 二分

    D2. Magic Powder - 2 time limit per test 1 second memory limit per test 256 megabytes input standard ...

  9. Magic Powder - 2 (CF 670_D)

    http://codeforces.com/problemset/problem/670/D2 The term of this problem is the same as the previous ...

随机推荐

  1. WinRAR 代码执行漏洞复现

    影响版本: WinRAR < 5.70 Beta 1 Bandizip    < = 6.2.0.0 好压(2345压缩)    < = 5.9.8.10907 360压缩    & ...

  2. for /f命令之—Delims和Tokens用法&总结

    在For命令语踞饽参数F中,最难理解的就是Delims和Tokens两个选项,本文简单的做一个比较和总拮.“For /f”常用来解析文本,读取字符串.分工上,delims负责切分字符串,而tokens ...

  3. [Python] 牛顿插值

    插值公式为: 差商递归公式为: # -*- coding: utf-8 -*- #Program 0.4 Newton Interpolation import numpy as np import ...

  4. zend_soap做webservice的使用方法

      只用到zend_soap包中的Zend_Soap_Server,Zend_Soap_AutoDiscover和Zend_Soap_Client三个类 首先要注意ZF是调用php的soap扩展,所以 ...

  5. 使用SharedPreferences存储数据

    SharedPreferences把数据保存在指定名称的XML文件中,文件地址在/data/data/包名/Shared_Prefs/文件夹中,具体是通过map形式保存. 保存数据: SharedPr ...

  6. elk6.22

    启动错误: 参考网站:https://blog.csdn.net/feinifi/article/details/73633235?utm_source=itdadao&utm_medium= ...

  7. zabbix微信报警

    [root@LinuxS04 jiaoben]# ./weixin 联系人 baojing baojingok[root@LinuxS04 jiaoben]# pwd/usr/local/zabbix ...

  8. 3. HashMap和JSONObject用法

    <%@page import="net.sf.json.JSONObject"%><%@page import="java.util.List" ...

  9. leetcode171

    public class Solution { private int ConvertToC(char c) { ; switch (c) { case 'A': case 'a': rnt = ; ...

  10. Spring boot Tomcat配置

    来自: https://www.cnblogs.com/a8457013/p/7687764.html