姓名:王胤皓,校区:和谐校区,考试时间: 2024 2024 2024 年 10 10 10 月 5 5 5 日 9 : 00 : 00 9:00:00 9:00:00~ 12 : 30 : 00 12:30:00 12:30:00,学号: S 07738 S07738 S07738
请关注作者的 B 站,谢谢~链接
CSP-J Day 5 5 5 模拟赛补题报告
前言
考了我们班 Rank 2 2 2。
分数
T1 milk: A c c e p e t e d 100 \color{green}Accepeted\space100 Accepeted 100
T2 traary: A c c e p e t e d 100 \color{green}Accepeted\space100 Accepeted 100
T3 usagi: W r o n g _ A n s w e r 25 \color{red}Wrong\_Answer\space25 Wrong_Answer 25
T4 missiles: W r o n g _ A n s w e r 5 \color{red}Wrong\_Answer\space5 Wrong_Answer 5
T1
题面
思路
首先排序,然后贪心,累加一下,就行了。
赛时 A c c e p e t e d \color{green}{Accepeted} Accepeted 代码
#include<bits/stdc++.h>
using namespace std;
struct node{
int num,money;
}a[200005];
bool cmp(node a,node b){
if(a.money==b.money) return a.num>b.num;
else return a.money<b.money;
}
int main(){
freopen("milk.in","r",stdin);
freopen("milk.out","w",stdout);
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
int n,m;
cin>>n>>m;
for(int i=1; i<=n; i++){
cin>>a[i].num>>a[i].money;
}
sort(a+1,a+n+1,cmp);
long long ans=0ll;
for(int i=1; i<=n; i++){
if(m>=a[i].num){
m-=a[i]