问题描述
小U是一位努力的学生,她正在申请奖学金。她修了nn门课程,每门课程有一个对应的学分aiai,并取得了一个成绩bibi。学校的奖学金评定要求是:小U所有课程的加权平均分不低于标准XX,并且所有课程的成绩都及格(即每门课的成绩不得低于6060分)。小U想知道她是否满足奖学金的申请条件。
测试样例
样例1:
输入:
n = 4, x = 75, a = [4, 3, 2, 1], b = [80, 70, 90, 60]
输出:True
样例2:
输入:
n = 3, x = 85, a = [3, 2, 5], b = [90, 85, 88]
输出:True
样例3:
输入:
n = 5, x = 80, a = [2, 2, 3, 1, 4], b = [78, 80, 79, 85, 88]
输出:True
样例4:
输入:
n = 6, x = 70, a = [4, 3, 2, 1, 2, 3], b = [60, 72, 65, 90, 85, 95]
输出:True
样例5:
输入:
n = 4, x = 90, a = [2, 2, 2, 2], b = [89, 91, 92, 85]
输出:False
import java.util.Arrays;public class Main {public static boolean solution(int n, int x, int[] a, int[] b) {for (int i = 0; i < n; i++) {if (b[i] < 60) {return false;}}int sum = Arrays.stream(a).sum();int score=0;for(int i=0;i<n;i++){score+=a[i]*b[i];}if(score*1.0/sum>=x){return true;}return false;}public static void main(String[] args) {System.out.println(solution(4, 75, new int[]{4, 3, 2, 1}, new int[]{80, 70, 90, 60}) == true);System.out.println(solution(3, 85, new int[]{3, 2, 5}, new int[]{90, 85, 88}) == true);System.out.println(solution(5, 80, new int[]{2, 2, 3, 1, 4}, new int[]{78, 80, 79, 85, 88}) == true);System.out.println(solution(6, 70, new int[]{4, 3, 2, 1, 2, 3}, new int[]{60, 72, 65, 90, 85, 95}) == true);System.out.println(solution(4, 90, new int[]{2, 2, 2, 2}, new int[]{89, 91, 92, 85}) == false);}
}