wei345 @ 2024-10-15 18:50:37
测试点信息 4ms/564.00KB AC
Accepted, 得分 20.ok accepted 3ms/556.00KB AC
Accepted, 得分 20.ok accepted 4ms/564.00KB WA
Wrong Answer.wrong answer On line 1 column 1, read 1, expected 9. 3ms/564.00KB AC
Accepted, 得分 20.ok accepted 0ms/0B RE
Runtime Error. Received signal 11: Segmentation fault with invalid memory reference.
#include<bits/stdc++.h>
using namespace std;
struct ns{
int x,y;
}q[1001];
bool cmp(ns z,ns z1){
return z.x>z1.x;
}
int n,a,s,x[1001],b,y[1011],ans;
int main(){
std::cin>>n>>s>>a>>b;
for(int i=1;i<=n;i++){
cin>>q[i].x>>q[i].y;
}
sort(q+1,q+n+1,cmp);
for(int i=1;i<=n;i++){
if(q[i].x<=a+b&&q[i].y<=s){
s-=q[i].y;
ans++;
}
}
cout<<ans;
return 0;
}
by wwwidk1234 @ 2024-10-15 19:13:44
@wei345
by CHkujiu @ 2024-10-15 19:14:28
稻花香里说丰年,听取WA声一片
by wwwidk1234 @ 2024-10-15 19:17:21
@wei345 你这思路很明显不对吧。要按照花费的力气排序。
帮你改过了:
// Problem: P1478 陶陶摘苹果(升级版)
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P1478
// Memory Limit: 125 MB
// Time Limit: 1000 ms
// I'm Jiaming and Neuvillette's _____!
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
using namespace std;
struct ns{
int x,y;
}q[5001];
bool cmp(ns z,ns z1){
return z.y<z1.y;
}
int n,a,s,x[5001],b,y[5011],ans;
int main(){
std::cin>>n>>s>>a>>b;
for(int i=1;i<=n;i++){
cin>>q[i].x>>q[i].y;
}
sort(q+1,q+n+1,cmp);
for(int i=1;i<=n;i++){
if(q[i].x<=a+b&&q[i].y<=s){
s-=q[i].y;
ans++;
}
}
cout<<ans;
return 0;
}
by wwwidk1234 @ 2024-10-15 19:18:08
@wei345 诶不是你这主页背景
by wei345 @ 2024-10-15 19:19:58
谢谢