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. 腾讯x5Webview取代原生android Webview

    一.官方地址: https://x5.tencent.com/tbs/ 二.不需要申请开发者,QQ直接登录,下载即可集成到项目中. 三.与原生的webview对比优势 1) 速度快:相比系统webvi ...

  2. js 操作数组(过滤对应数据)

    过滤掉相应数据 var fileList = { "85968439868a92": [{name: 'food.jpeg'}, {name: 'ood.jpeg'}], &quo ...

  3. 我的第一个python web开发框架(3)——怎么开始?

    小白与小美公司经过几次接触商谈,好不容易将外包签订了下来,准备开始大干一场.不过小白由于没有太多的项目经验,学过python懂得python的基本语法,在公司跟着大家做过简单功能,另外还会一些HTML ...

  4. HDU 5974 数学

    A Simple Math Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Ot ...

  5. 跨主机使用 Rex-Ray volume - 每天5分钟玩转 Docker 容器技术(77)

    上一节我们在 docker1 上的 MySQL 容器中使用了 Rex-Ray volume mysqldata,更新了数据库.现在容器已经删除,今天将演示在 docker2 中重新使用这个卷. 在 d ...

  6. Fiddler屏蔽某些url的抓取方法

    在用Fiddler调试网页的时候,可能某些频繁的ajax轮询请求会干扰我们,可以通过以下方法屏蔽某些url的抓取. 在需要屏蔽的url行上右键---->“Filter Now”-----> ...

  7. 翻译 | 关键CSS和Webpack: 减少阻塞渲染的CSS的自动化解决方案

    原文地址: Critical CSS and Webpack: Automatically Minimize Render-Blocking CSS 原文作者: Anthony Gore 译者: 蜗牛 ...

  8. Promise 对象

    Promise 对象用于处理异步请求,保存一个异步操作最终完成(或失败)的结果 语法 new Promise( /* executor */ function(resolve, reject) {.. ...

  9. (10.11)Java第一小步

    在度过大一和大二浑浑噩噩的咸鱼生活之后,我决定 开始为自己的未来负责,开始学习自己喜欢的Java,同时决定以这篇博客来开启自己的博客之旅和Jaca的学习之路. 以后我也会陆续在博客园更新自己的博客,记 ...

  10. Scrapy框架--使用cookie

    CookieMiddleware class scrapy.downloadermiddlewares.cookies.CookieMiddlewar 该中间件使得爬取需要cookie(例如使用ses ...