J. Bottles
time limit per test

2 seconds

memory limit per test

512 megabytes

input

standard input

output

standard output

Nick has n bottles of soda left after his birthday. Each bottle is described by two values: remaining amount of soda ai and bottle volume bi (ai ≤ bi).

Nick has decided to pour all remaining soda into minimal number of bottles, moreover he has to do it as soon as possible. Nick spends x seconds to pour x units of soda from one bottle to another.

Nick asks you to help him to determine k — the minimal number of bottles to store all remaining soda and t — the minimal time to pour soda into k bottles. A bottle can't store more soda than its volume. All remaining soda should be saved.

Input

The first line contains positive integer n (1 ≤ n ≤ 100) — the number of bottles.

The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 100), where ai is the amount of soda remaining in the i-th bottle.

The third line contains n positive integers b1, b2, ..., bn (1 ≤ bi ≤ 100), where bi is the volume of the i-th bottle.

It is guaranteed that ai ≤ bi for any i.

Output

The only line should contain two integers k and t, where k is the minimal number of bottles that can store all the soda and t is the minimal time to pour the soda into k bottles.

Examples
Input
4
3 3 4 3
4 7 6 5
Output
2 6
Input
2
1 1
100 100
Output
1 1
Input
5
10 30 5 6 24
10 41 7 8 24
Output
3 11
Note

In the first example Nick can pour soda from the first bottle to the second bottle. It will take 3 seconds. After it the second bottle will contain 3 + 3 = 6 units of soda. Then he can pour soda from the fourth bottle to the second bottle and to the third bottle: one unit to the second and two units to the third. It will take 1 + 2 = 3 seconds. So, all the soda will be in two bottles and he will spend 3 + 3 = 6 seconds to do it.

题意:给你n个杯子 给出n个杯子的初始水的体积以及杯子的体积 现在倒水 使得用最少个数的杯子装所有的水 并且在倒水的过程中 使得倒出的水尽量的少

题解:爆搜TLE  背包处理 orzzz 太菜了

dp[i][j]表示用i个杯子容量为j最多能装多少水 注意这个j的范围为杯子的体积和 (可能所选的i个杯子 就算装有全部的水 也不会装满)

 /******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
#include<bits/stdc++.h>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<math.h>
#include<vector>
#include<string>
#include<stdio.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
#define A first
#define B second
const int mod=;
const int MOD1=;
const int MOD2=;
const double EPS=0.00000001;
typedef __int64 ll;
const ll MOD=;
const int INF=;
const ll MAX=1ll<<;
const double eps=1e-;
const double inf=~0u>>;
const double pi=acos(-1.0);
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
int n;
struct node
{
int a,b;
}N[];
int dp[][];
bool cmp(struct node aa,struct node bb)
{
if(aa.b>bb.b)
return true;
if(aa.b==bb.b)
{
if(aa.a>bb.a)
return true;
}
return false;
}
int main()
{
scanf("%d",&n);
int m=;
int mm;
int mm2=;
for(int i=;i<=n;i++)
{
scanf("%d",&N[i].a);
m+=N[i].a;
}
mm=m;
for(int i=;i<=n;i++)
{
scanf("%d",&N[i].b);
mm2+=N[i].b;
}
sort(N+,N++n,cmp);
int num=;
while()
{
m-=N[++num].b;
if(m<=)
break;
}
memset(dp,,sizeof(dp));
for(int i=;i<=num;i++)
for(int j=;j<=mm2;j++)
dp[i][j]=-INF;
dp[][]=;
for(int j=;j<=n;j++)
{
for(int k=mm2;k>=N[j].b;k--)
{
for(int l=;l<=num;l++){
dp[l][k]=max(dp[l][k],dp[l-][k-N[j].b]+N[j].a);
}
}
}
int ans=;
for(int i=mm2;i>=mm;i--)
if(dp[num][i])
ans=max(ans,dp[num][i]);
printf("%d %d\n",num,mm-ans);
return ;
}
/*
10
18 42 5 1 26 8 40 34 8 29
18 71 21 67 38 13 99 37 47 76
3 100
*/

2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) J dp 背包的更多相关文章

  1. Codeforces1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)总结

    第一次打ACM比赛,和yyf两个人一起搞事情 感觉被两个学长队暴打的好惨啊 然后我一直做傻子题,yyf一直在切神仙题 然后放一波题解(部分) A. Find a Number LINK 题目大意 给你 ...

  2. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror) Solution

    从这里开始 题目列表 瞎扯 Problem A Find a Number Problem B Berkomnadzor Problem C Cloud Computing Problem D Gar ...

  3. codeforce1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) 题解

    秉承ACM团队合作的思想懒,这篇blog只有部分题解,剩余的请前往星感大神Star_Feel的blog食用(表示男神汉克斯更懒不屑于写我们分别代写了下...) C. Cloud Computing 扫 ...

  4. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)

    A. Find a Number 找到一个树,可以被d整除,且数字和为s 记忆化搜索 static class S{ int mod,s; String str; public S(int mod, ...

  5. 2018.10.20 2018-2019 ICPC,NEERC,Southern Subregional Contest(Online Mirror, ACM-ICPC Rules)

    i207M的“怕不是一个小时就要弃疗的flag”并没有生效,这次居然写到了最后,好评=.= 然而可能是退役前和i207M的最后一场比赛了TAT 不过打得真的好爽啊QAQ 最终结果: 看见那几个罚时没, ...

  6. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) Solution

    A. Find a Number Solved By 2017212212083 题意:$找一个最小的n使得n % d == 0 并且 n 的每一位数字加起来之和为s$ 思路: 定义一个二元组$< ...

  7. 2018-2019 ICPC, NEERC, Southern Subregional Contest

    目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...

  8. Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest

    2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...

  9. 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror) in codeforces(codeforces730)

    A.Toda 2 思路:可以有二分来得到最后的数值,然后每次排序去掉最大的两个,或者3个(奇数时). /************************************************ ...

随机推荐

  1. C++-多重继承的注意点

    1, 钻石型多重继承如果不想要底部的类有重复的变量,则需要声明为virtual继承 class File{...}; class InputFile: virtual public File{..}; ...

  2. C#根据当前日期获取星期和阴历日期

    private string GetWeek(int dayOfWeek) { string returnWeek = ""; switch (dayOfWeek) { case ...

  3. AIX查看内存卡槽

    1.lscfg -vp|grep Processor 2.lscfg -vp|grep -p Memory

  4. iOS 高效添加圆角效果实战讲解

    圆角(RounderCorner)是一种很常见的视图效果,相比于直角,它更加柔和优美,易于接受.但很多人并不清楚如何设置圆角的正确方式和原理.设置圆角会带来一定的性能损耗,如何提高性能是另一个需要重点 ...

  5. Android ContentProvider的实现

    当Android中的应用需要访问其他应用的数据时,用ContentProvider可以很好的解决这个问题.今天介绍一下ContentProvider的用法. 首先开发ContentProvider有两 ...

  6. equals() 与 hashcode() 的区别与联系

    两者都是从Object类继承的方法,Object中equals方法比较的是this和参数传进来的对象的引用地址是否相同,这样的话,equals返回值为true的必要充分条件就是两者指向同一个对象,那么 ...

  7. Quartz 2D--长方形和线条绘图

    今天原本想模仿2048 游戏的. 但是在设计背景环境时,涉及到绘图的知识!于是就开始对绘图进行了一翻学习. 若想自己绘图必须 写自己的View(继承UICView):然后重写UIView 中的 dra ...

  8. 立体透视 perspective transform-style 倾斜旋转

    1.perspective 是设置镜头距离,距离越远视图越小,视图越近,视图越大.就像相机焦距一样.其只对子元素产生效果. 2.transform-style: preserve-3d 设置3d效果, ...

  9. Navicat提示Access violation at address 004E9844 in module ‘navicat.exe’

    今天在联系MySQL 数据库表的练习时,出现了一下问题: 内存越界问题,最好重新注册下Windows的动态链接库 首先“开始”—“运行”—“cmd” 在打开的dos窗口中运行“for %1 in (% ...

  10. lightoj1027

    //Accepted 1688 KB 0 ms //概率简单题 //假设我们在n个门前加个起点,在n个门后加个终点,起点可以到达n个门, //为正的门可以到达终点,为负的回到起点 //则假设我们从起点 ...