hdu 3594 Buy Computers【水题】
来源:互联网 发布:廊坊用友软件 编辑:程序博客网 时间:2024/05/09 05:16
Leyni goes to a second-hand market for old computers. There are n computers at the sale and computer i costs ci Yuan. Some computers with a negative price mean that their owners will pay Leyni if he buys them. Leyni can carry at most m computers, and he won’t go to the market for a second time.
Leyni wonders the maximum sum of money that he can earn.
InputThere are multiple test cases. The first line of input is an integer T indicating the number of test cases. Then T test cases follow.
For each test case:
Line 1. This line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) indicating the amount of computers at the sale and the amount of computers that Leyni can carry.
Line 2. This line contains n space-separated integers ci (-1000 ≤ ci ≤ 1000) indicating the prices of the computers.
OutputFor each test case:
Line 1. Output the maximum sum of money that Leyni can earn.
Sample Input1
5 3
-5 3 2 1 -4
Sample Output9
Source哈理工2012春季校赛 - 网络预选赛Author齐达拉图@HRBUST题目大意:就是初始的时候,身上最多可以带m个电脑去卖,负值表示这个店铺买我一个电脑的支付金额,问我这一趟最多能赚多少钱。
思路:
sort一下,累加最小值,输出负值即可。
Ac代码:
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int a[50000];int main(){ int t; scanf("%d",&t); while(t--) { int n,m; scanf("%d%d",&n,&m); for(int i=0;i<n;i++) { scanf("%d",&a[i]); } sort(a,a+n); int output=0; int tt=m; for(int i=0;i<n;i++) { if(tt==0)break; if(a[i]<0) { output+=a[i]; tt--; } } printf("%d\n",-output); }}
- hdu 3594 Buy Computers【水题】
- Hust oj 1369 Buy Computers(水题)
- HDU 1913 Computers
- HDU 1913 Computers
- hdu acm 1913 Computers
- hdu 1913 computers
- HDU 1913 Computers (解题报告)
- Computers
- POJ 3486 & HDU 1913 Computers(dp)
- HDU Buy the Ticket
- Buy the Ticket HDU
- HDU Buy the Ticket
- Simple Computers
- ELECTRONIC COMPUTERS
- Simple Computers
- Computers zoj
- poj3486 Computers
- Quantum Computers
- 一个互联网app的开发设计(技术选型和架构)
- 变量、常量 的区别
- 第一次谈判经历
- java 面试题
- DrawCall优化
- hdu 3594 Buy Computers【水题】
- 站在对方角度
- 32位和64位系统区别及int字节数
- 项目各阶段版本类别- alpha beta rc stable
- 4.3 C语言基本运算符
- 4.4 C语言for循环语句
- 剑指Offer:面试题6——重建二叉树(java实现)
- 对象导论之伴随多态的可互换对象
- 求圆圈中剩下的最后一个数字