XieLee @ 2023-02-07 14:11:07
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.Arrays;
import java.util.Comparator;
class Main{
static StreamTokenizer st=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
public static void main(String[] args) throws IOException {
int n=nextInt();
int limStrength=nextInt();
int bandeng=nextInt();
int gao=nextInt();
Ping[] arr=new Ping[n];
for(int i=0;i<n;i++)
{
Ping p=new Ping();
p.setGao(nextInt());
if(p.getGao()<bandeng+gao)
{
p.setLi(nextInt());
}
else
{
nextInt();
p.setLi(Integer.MAX_VALUE);
}
arr[i]=p;
}
Arrays.sort(arr,new Comparator<Ping>() {
@Override
public int compare(Ping o1, Ping o2) {
// TODO 自动生成的方法存根
return o1.getLi()-o2.getLi();
}
});
int i=0;
int count=0;
while(i<n&&limStrength>=arr[i].getLi())
{
limStrength=limStrength-arr[i].getLi();
count++;
i++;
}
System.out.println(count);
}
static int nextInt() {
try {
st.nextToken();
} catch (IOException e) {
}
return (int)st.nval;
}
}
class Ping{
int gao;
int li;
public int getGao() {
return gao;
}
public void setGao(int gao) {
this.gao = gao;
}
public int getLi() {
return li;
}
public void setLi(int li) {
this.li = li;
}
}
如上,WA了第二个和第五个,求助
by XieLee @ 2023-02-07 14:13:30
大雾!
这凳子是不是直接加身高里面就行,没看懂有啥用,感觉错在这,但是没找到问题
by XieLee @ 2023-02-08 08:06:40
已解决问题,无需回复!感谢查看