import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class Discount {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
int moneyCount = sc.nextInt();
List<Person> list = new ArrayList<Person>();
for (int i = 0; i < num; i++) {
Person p = new Person();
p.setDiscount(sc.nextDouble());
p.setMoney(sc.nextInt());
list.add(p);
}
// 计算最大上限
int maxMoney = 0;
for (Person p1 : list) {
maxMoney += p1.getMoney();
}
// 对折扣进行排序
Collections.sort(list);
// 如果总价小于所有折扣率上线之和
// 则用一循环从折扣率最低一直到折扣到总数
int minMoney = 0;
if (maxMoney > moneyCount) {
// 存放前n项和
int current3 = 0;
int current = 0, i, current2 = 0;
for (i = 0; i < list.size(); i++) {
current += list.get(i).getMoney();
if (current > moneyCount) {
break;
}
}
for (int j = 0; j < i; j++) {
current2 += list.get(j).getMoney() * list.get(j).getDiscount();
}
for (int x = 0; x < i; x++) {
current3 += list.get(x).getMoney();
}
minMoney = (int) (current2 + (moneyCount - current3)
* list.get(i).getDiscount());
System.out.println(minMoney);
}
// 如果总价大于所有折扣率上线之和那么就是所有人都折扣完,剩余的钱按照原价付
if (maxMoney <= moneyCount) {
int currentMoney1 = 0, currentMoney2 = 0;
for (int i = 0; i < list.size(); i++) {
currentMoney2 += list.get(i).getMoney();
currentMoney1 += (int) (list.get(i).getMoney() * list.get(i)
.getDiscount());
}
minMoney = currentMoney1 + (moneyCount - currentMoney2);
System.out.println(minMoney);
}
}
}
class Person implements Comparable<Person> {
private double discount;
private int money;
public double getDiscount() {
return discount;
}
public void setDiscount(double discount) {
this.discount = discount;
}
public int getMoney() {
return money;
}
public void setMoney(int money) {
this.money = money;
}
// 用于比较
public int compareTo(Person p) {
if (discount != p.getDiscount()) {
// 升序排列
if (discount < p.getDiscount()) {
return -1;
}
if (discount > p.getDiscount()) {
return 1;
}
return 0;
} else {
// 降序排列
return p.getMoney() - money;
}
}
// 判断两个对象是否相等
public boolean equals(Object obj) {
if (obj instanceof Person) {
Person p = (Person) obj;
if ((discount == p.getDiscount()) && (money == p.getMoney())) {
return true;
} else {
return true;
}
} else {
return false;
}
}
}

baidu_26663457
- 粉丝: 0
最新资源
- 基于Cars im和Matlab的CACC协同式自适应巡航模型构建与模糊MPC算法实现 专业版
- SQL Server Management Studio 17.9.1语言切换中文问题解决,故障:先安装了英文,卸载后再安装中文,还是英文界面
- MATLAB环境下自适应Chirp模态分解算法:一维时间序列分析与故障诊断工具
- 红外弱小目标检测-IPI算法
- 机器人技术中质心侧偏角Simulink程序的设计与实现
- 南澳多端柔性直流输电示范工程:MMC-HVDC模型与Fortran源代码分享 全面版
- DevEco Studio安装本地模拟器时出现的问题及解决
- 基于S7-1200 PLC的四层电梯仿真模拟程序:博图V15与WinCC动画功能实现
- LabVIEW解析CAN报文与DBC文件:支持多格式离线解析及自定义特征索引ID的应用
- 飞翔的荷兰人带你轻松入门目标检测第一季(Yolo-v1)
- Python 项目示例:一个简单的 学生管理系统
- MATLAB实现基于留出法和k折交叉验证的六种神经网络分类预测
- 红外弱小目标检测-IPI算法
- 基于MATLAB的FFT频谱分析与滤波技术及其在波形数据处理中的应用
- LabVIEW叶片频率测量系统源码解析:安捷伦34401数据采集与处理实践
- 四旋翼飞行器PID与模糊PID控制:基于Simulink与Matlab的仿真优化及自主学习实践
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈


