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. HDU 3642 扫描线(立方体体积并)

    Get The Treasury Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  2. iOS解决两个静态库的冲突 duplicate symbol

    http://blog.163.com/023_dns/blog/static/118727366201391544630380/ 场景: 解决TencentOpenAPI.framework与Zba ...

  3. HDOJ 1754 I Hate It 线段树 第二题

    I Hate It Problem Description 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少.这让很多学生很反感. 不管你喜不喜欢,现在需要你做的是,就 ...

  4. POJ 2559 Program C

    Submit Status Practice POJ 2559 Description A histogram is a polygon composed of a sequence of recta ...

  5. sql 语句中使用条件判断case then else end

    sql 语句中使用条件判断case then else end范例: SELECT les.[nLessonNo] FROM BS_Lesson AS les WHERE les.[sClassCod ...

  6. SharePoint表单和工作流 - Nintex篇(六)

    博客地址 http://blog.csdn.net/foxdave 接上篇点击打开链接 在工作流Action的配置对话框中,点击"Edit with Nintex Forms",上 ...

  7. 解决使用IIS5.0配置的FTP服务器,客户端浏览器访问时无法获取目录列表的问题。

    我在windows xp sp3下利用iis构架了FTP服务器,允许且只允许匿名用户登陆.但刚开始配置好后,不管是使用命令行模式还是使用浏览器都发现无法访问. 于是怀疑防火墙屏蔽端口所致,果不其然,在 ...

  8. Mysql5.0以下 手工注入

    order by 20 www. .com/product/introduction.php?id=-65 UNION SELECT user(),2 www. .com/product/introd ...

  9. vega prime 1.2 (视景仿真)

    Vega Prime 1.2 (视景仿真) MPI的视景仿真渲染工具Vega是世界上领先的应用于实时视景仿真.声音仿真和虚拟现实等领域的软件环境,它用来渲染战场仿真.娱乐.城市仿真.训练模拟器和计算可 ...

  10. windows8.1 plsql连接oracle

    http://pan.baidu.com/share/link?shareid=3782452820&uk=3557941237 http://pan.baidu.com/share/link ...