求看代码有什么问题
我用了暴力解法,代码逻辑没问题,找了几个示例都通过了,就是系统最终通过不了,大家能帮忙看看代码问题出现在哪吗
题目:
某比赛已经进入了淘汰赛阶段,已知共有n名选手参与了此阶段比赛,他们的得分分别是a_1,a_2….a_n,小美作为比赛的裁判希望设定一个分数线m,使得所有分数大于m的选手晋级,其他人淘汰。
但是为了保护粉丝脆弱的心脏,小美希望晋级和淘汰的人数均在[x,y]之间。
显然这个m有可能是不存在的,也有可能存在多个m,如果不存在,请你输出-1,如果存在多个,请你输出符合条件的最低的分数线。
数据范围:,
进阶:时间复杂度,空间复杂度
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in); // 读第一行数据
String s = sc.nextLine();
String[] t = s.split(" ");
int n = Integer.parseInt(t[0]);
int x = Integer.parseInt(t[1]);
int y = Integer.parseInt(t[2]);
String s2 = sc.nextLine(); // 读第二行分数
String[] t2 = s2.split(" ");
for(int i = 0; i < n; i ++) { // 遍历查验每个分数能否做为区分度m
int m = Integer.parseInt(t2[i]);
int up = 0, out = 0; // 晋级、淘汰人数
for(int j = 0; j < n; j ++) {
int scor = Integer.parseInt(t2[j]);
if(scor <= m) out ++;
else up ++;
}
if(out >= x && out <= y && up >= x && up <= y) { // 晋级淘汰人数满足条件
System.out.println(m);
return;
}
}
System.out.println(-1);
}
}
顺丰集团工作强度 379人发布
