C:Dawn-K's water (The Preliminary Contest for ICPC Asia Shenyang 2019)

Dawn-K recently discovered a very magical phenomenon in the supermarket of Northeastern University: The large package is not necessarily more expensive than the small package.

On this day, Dawn-K came to the supermarket to buy mineral water, he found that there are nn types of mineral water, and he already knew the price pp and the weight cc (kg) of each type of mineral water. Now Dawn-K wants to know the least money aa he needs to buy no less than mm kilograms of mineral water and the actual weight bb of mineral water he will get. Please help him to calculate them.

Input

The input consists of multiple test cases, each test case starts with a number nn (1 \le n \le 10^31≤n≤103) -- the number of types, and mm (1 \le m \le 10^41≤m≤104) -- the least kilograms of water he needs to buy. For each set of test cases, the sum of nn does not exceed 5e45e4.

Then followed n lines with each line two integers pp (1 \le p \le 10^91≤p≤109) -- the price of this type, and cc (1 \le c \le 10^41≤c≤104) -- the weight of water this type contains.

Output

For each test case, you should output one line contains the minimum cost aa and the weight of water Dawn-K will get bb. If this minimum cost corresponds different solution, output the maximum weight he can get.

(The answer aa is between 11 and 10^9109, and the answer bb is between 11 and 10^4104)

样例输入复制

3 3
2 1
3 1
1 1
3 5
2 3
1 2
3 3

样例输出复制

3 3
3 6


#include <iostream>
#include <cmath>
#include <map>
#include <queue>
#include <memory.h>
#include <algorithm>

using namespace std;

long long w[1010],v[1010],arc[10010];

int main()
{
    std::ios::sync_with_stdio(false);
    int n,m;
    while(cin>>n>>m)
    {
        for(int i=0;i<10010;i++)
            arc[i]=1e10+100;
        arc[0]=0;
        for(int i=0;i<n;i++)
            cin>>w[i]>>v[i];
        for(int i=0;i<n;i++)
        {
            for(int j=v[i];j<=10000;j++)
            {
                arc[j]=min(arc[j],arc[j-v[i]]+w[i]);
            }
        }
        int mini=m;
        for(int i=m+1;i<=10000;i++)
        {
            if(arc[i]<=arc[m]&&arc[i]<=arc[mini])
            {
                mini=i;
            }
        }
        cout<<arc[mini]<<‘ ‘<<mini<<endl;
    }
    return 0;
}

C:Dawn-K's water (The Preliminary Contest for ICPC Asia Shenyang 2019)

原文地址:https://www.cnblogs.com/Shallow-dream/p/11520294.html

时间: 2024-09-27 08:05:19

C:Dawn-K's water (The Preliminary Contest for ICPC Asia Shenyang 2019)的相关文章

The Preliminary Contest for ICPC Asia Shenyang 2019

The Preliminary Contest for ICPC Asia Shenyang 2019 Texas hold'em Poker #include <bits/stdc++.h> using namespace std; const int maxn=1e6+10; int num[1000]; int shun(){ for (int i=15;i>=5;i--){ if (num[i]&&num[i-1]&&num[i-2]&&a

The Preliminary Contest for ICPC Asia Shenyang 2019 H. Texas hold&#39;em Poker

题目链接:https://nanti.jisuanke.com/t/41408 题目意思很简单,就是个模拟过程. 1 #include <iostream> 2 #include <cstring> 3 #include <algorithm> 4 #include <cstdio> 5 #include <map> 6 #define rep(i,j,k) for(int i = (j); i <= (k); ++i) 7 #define

The Preliminary Contest for ICPC Asia Shenyang 2019 F. Honk&#39;s pool

题目链接:https://nanti.jisuanke.com/t/41406 思路:如果k的天数足够大,那么所有水池一定会趋于两种情况: ① 所有水池都是一样的水位,即平均水位 ② 最高水位的水池和最低水位的水池高度只相差一个高度,且最低水位一定是平均水位 如果k给了个限制: 我们当然需要先算出所有水池高度的平均值. 然后从低到高排序,二分小于平均值的水位,二分高于平均值的水位, 然后判断二分的预期值需要的天数是否小于等于k.然后二分找出最低水位的最大值, 最高水位的最小值,两者相减就是答案了

The Preliminary Contest for ICPC Asia Shanghai 2019 C Triple(FFT+暴力)

The Preliminary Contest for ICPC Asia Shanghai 2019 C Triple(FFT+暴力) 传送门:https://nanti.jisuanke.com/t/41400 题意: 给你三个数组a,b,c,要你求有多少个三元组(i,j,k),使得 \[ \begin{array}{l}{\left|A_{i}-B_{j}\right| \leq C_{k}, \text { and }} \\ {\left|B_{j}-C_{k}\right| \leq

The Preliminary Contest for ICPC Asia Nanjing 2019/2019南京网络赛——题解

(施工中……) 比赛传送门:https://www.jisuanke.com/contest/3004 D. Robots(期望dp) 题意 给一个DAG,保证入度为$0$的点只有$1$,出度为$0$的点只有$n$. 现在一个机器人从$1$出发,每天都会以相同的概率前往相邻节点之一或静止不动. 每天机器人消耗的耐久等于经过的天数. 求机器人到点$n$期望消耗的耐久. 划水划的很愉快,唯一一道做出来的题.但是和题解做法不同(感觉我的方法麻烦),因此砸了3h在这题上面(正在试图读懂题解ing). 设

The Preliminary Contest for ICPC Asia Xuzhou 2019

A What is better? 推不出来,写个程序打表,用扩展中国剩余定理合并,居然会溢出longlong,还好不会溢出__int128(赛后exit(-1)测试),实际证明溢出返回-1是不靠谱的,毕竟后面可以又把它搞小了. #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef __int128 lll; const int MAXK = 10 + 5; void exgcd(lll a, ll

The Preliminary Contest for ICPC Asia Shanghai 2019

D. Counting Sequences I 暴力搜索. #include <bits/stdc++.h> using namespace std; typedef long long ll; const int MOD = 1000000007; map<vector<short>, short> m; vector<short> vec; void calc(int num1) { vector<short> tmp; if(num1) t

The Preliminary Contest for ICPC Asia Nanchang 2019

目录 Solutions B. Fire-Fighting Hero E. Magic Master Link Solutions B. Fire-Fighting Hero 题意: 思路: dijkstra最短路 先以 hero 为起点 跑一遍 dijkstra 建立 起点 \(p\) 并与各 fire-fighting point 建立权为 \(0\) 的边,跑一遍 dijkstra 第二次 dijkstra 中 dis[i] 为各 fire-fighting point 到各点的最短路径中

The Preliminary Contest for ICPC Asia Nanjing 2019 D. Robots(概率dp)

题目链接:https://nanti.jisuanke.com/t/41301 题目大意: 给定一个没有循环的有向图,它从节点1开始,到节点n结束. 有一个机器人从1开始,每天都会以相同的概率前往相邻节点之一或静止不动.每天机器人的耐久性消耗量等于经过的天数. 请计算机器人到达节点n时的预期耐久性消耗量. 保证只有一个节点(节点1)的in-degree等于00,并且只有一个节点(节点n)的out-degree等于0.并且图中没有多个边缘. 解题思路: 设dp[i]为从i到达终点n的期望时间那么很