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.

/*
背包问题:最少用几个桶很简单能求出来。然后背包出这些桶最少
*/ /*
比赛的时候怎么就脑残的想到了贪心没想到背包啊!!!赛后出题真是啧啧啧
*/
#include <bits/stdc++.h>
using namespace std;
struct qwe
{
int a,b;
} e[];
int cmp(qwe x,qwe y)
{
return (x.b>y.b || (x.b==y.b && x.a>y.a));//体积大的排序,如果体积相同就按照已经有水多的的在前面
}
int cmp1(qwe x,qwe y)//按照体积小的排序
{
return (x.b<y.b);
}
int dp[][],s[];
int main()
{
//freopen("C:\\Users\\acer\\Desktop\\in.txt","r",stdin);
int n;
scanf("%d",&n);
int sum=;//总共有多少水
for(int i=;i<=n;i++)
scanf("%d",&e[i].a),sum+=e[i].a;
for(int i=;i<=n;i++)
scanf("%d",&e[i].b);
sort(e+,e++n,cmp);
int t=,q=;
int ans;
for(int i=;i<=n;i++)
{
t+=e[i].b;
if(t>=sum)
{
ans=i;
break;
}
}//找出最少的桶数
sort(e+,e++n,cmp1);
for(int i=;i<=n;i++)
s[i]=s[i-]+e[i].b;
memset(dp,0xBf,sizeof(dp));
dp[][]=;//dp[j][k]表示j个桶,最多装多少水
for(int i=;i<=n;i++)//用多少桶
{
for(int j=min(i,ans);j>;j--)
for (int k=s[i];k>=e[i].b;k--)
{
dp[j][k]=max(dp[j][k],dp[j-][k-e[i].b]+e[i].a);
}
}
int fin=;
for (int k=s[n];k>=sum;k--)
fin=max(fin,dp[ans][k]);
printf("%d %d\n",ans,sum-fin);
return ;
}

2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest J. Bottles的更多相关文章

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

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

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

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

  3. 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 ...

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

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

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

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

  6. 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, ...

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

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

  8. 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$ 思路: 定义一个二元组$< ...

  9. 【*2000】【2018-2019 ICPC, NEERC, Southern Subregional Contest C 】Cloud Computing

    [链接] 我是链接,点我呀:) [题意] [题解] 我们可以很容易知道区间的每个位置有哪些安排可以用. 显然 我们优先用那些花费的钱比较少的租用cpu方案. 但一个方案可供租用的cpu有限. 我们可以 ...

随机推荐

  1. Android 8.0 功能和 API

    Android 8.0 为用户和开发者引入多种新功能.本文重点介绍面向开发者的新功能. 用户体验 通知 在 Android 8.0 中,我们已重新设计通知,以便为管理通知行为和设置提供更轻松和更统一的 ...

  2. IOS SDWebImage实现基本原理详解(转载)

    1)当我门需要获取网络图片的时候,我们首先需要的便是URl没有URl什么都没有,获得URL后我们SDWebImage实现的并不是直接去请求网路,而是检查图片缓存中有没有和URl相关的图片,如果有则直接 ...

  3. 修改NSMutableArray中的元素时的注意事项

    最近做项目遇到从文件加载数组,并对数组中的元素进行操作的问题,特意写了个Demo,记录下要注意的东西: 代码如下: NSArray *array = @["]; NSMutableArray ...

  4. ASP.NET Core 2.0 使用支付宝PC网站支付

    前言 最近在使用ASP.NET Core来进行开发,刚好有个接入支付宝支付的需求,百度了一下没找到相关的资料,看了官方的SDK以及Demo都还是.NET Framework的,所以就先根据官方SDK的 ...

  5. 在分布式数据库中CAP原理CAP+BASE

    本篇博文的内容均来源于网络,本人只是整理,仅供学习! 一.关系型数据库 关系型数据库遵循ACID规则 事务在英文中是transaction,和现实世界中的交易很类似,它有如下四个特性: 1.A (At ...

  6. pygame_polygon

    今天我们要在窗口上绘制简单的多边形 1.认识几个简单的常用的颜色: black=(0,0,0) while=(255,255,255) red=(255,0,0) green=(0,255,0) bl ...

  7. 分享基于分布式Http长连接框架--架构模型

    我画了个简单的架构图来帮助说明: 其实为发布订阅架构模式. 生产者和消费者我们统一可理解为客户端,消息中间件可认为是服务端. 生产者和消费者做为客户端要跟服务端交互,则先通过代理订阅服务端,订阅成功后 ...

  8. qplot函数用法(转载)

    http://blog.csdn.net/u014801157/article/details/24372499 写的很全面 放在这里记录下

  9. js X年X周 转成 具体日期

    function getWeekDate(theyear,weekcount) { var year = theyear; var week = weekcount; if(year=="& ...

  10. Vue的条件渲染

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...