Hust oj 1369 Buy Computers(水题)
来源:互联网 发布:机器人授权系统源码 编辑:程序博客网 时间:2024/05/24 15:38
Leyni goes to a second-hand market for old computers. There aren 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 mostm 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 integerT indicating the number of test cases. Then T test cases follow.
For each test case:
Line 1. This line contains two space-separated integersn 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 integersci (-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的最大负数和是多少。。大水题
#include<cstdio>#include<iostream>#include<algorithm>using namespace std;const int maxn = 105;int sum;int n,m;int t;int a[maxn];int main(){ scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); for(int i=0;i<n;i++) { scanf("%d",&a[i]); } sum = 0; int num = 0; sort(a,a+n); for(int i=0;i<n;i++) { if(a[i] < 0 && num < m) { num++; sum += a[i]; } } printf("%d\n",-sum); } return 0;}
- Hust oj 1369 Buy Computers(水题)
- hdu 3594 Buy Computers【水题】
- Hust oj 2121 你猜猜(水题)
- Hust oj 2235 毒(水题)
- Hust oj 2125 钱多多(水题)
- Hust oj 1693 Difficult work(水题)
- Hust oj 2000 极差(水题)
- Hust oj 1720 Fibonacci Numbers(水题)
- Hust oj 1629 统计图(水题)
- Hust oj 1431 摞盘子(水题)
- Hust oj 1046 Balls Collision(水题)
- Hust oj 2084(大数)
- Hust oj 1394 XianGe的游戏I(水题)
- Hust oj 1197 Cuts the cake(水题)
- Hust oj 1384 Leyni, LOLI and Toasts(水题)
- Hust oj 2116 Maximum continuous product(水题)
- Hust oj 1673 2013新的旅程(水题)
- Hust oj 1754 Minimum Scalar Product(水题)
- flask + MongoDB 学习笔记(2):增改删查数据库
- 创建和使用一个新的系统调用
- 四种XML解析方式详解
- java int和float默认类型转换探究
- cocos2dx中的回调函数
- Hust oj 1369 Buy Computers(水题)
- shell(二)
- 带你了解面向对象的设计原则
- 如何优雅的实现界面统跳协议
- Java泛型-泛型通配符的使用
- jquery获取浏览器和屏幕的高度和宽度
- Android Studio安装以及部分说明
- 虚拟机类加载机制
- NEFU115 斐波那契的整除(数论水题)