网易 牛牛找工作java代码本地ide可以运行,在线通不过
import java.util.Scanner;
import java.util.HashMap;
public class Main{
public static void findjob(HashMap<Integer,Integer> job,HashMap<Integer,Integer> pep){
for(Integer pepkey:pep.keySet()){
int ai=pep.get(pepkey);//每个小伙伴的能力值
int temp=0;
for(Integer jobkey:job.keySet()){
int di=jobkey; //工作难度
int pi=job.get(jobkey); //报酬
//如果能小伙伴能力值大于工作难度
if(ai>=di){
if(temp<pi){
pep.put(pepkey, pi);
temp=pi;
}
}
}
}
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt(); //工作数量
int m=sc.nextInt(); //小伙伴数量
if(n==0||m==0){
System.out.print(0);
}else{
HashMap<Integer,Integer> job=new HashMap<Integer, Integer>(n);
HashMap<Integer,Integer> pep=new HashMap<Integer, Integer>(m);
while(sc.hasNextInt()&&sc.hasNextInt(m)){
int di=sc.nextInt();
int pi=sc.nextInt();
job.put(di,pi );
}
//job.put(10 ,1000 );
//job.put(1000000000 ,1001 );
for(int i=1;i<=m;i++){
int ai=sc.nextInt();
pep.put(i, ai);
}
//pep.put(2, 10);
// pep.put(3, 1000000000);
findjob(job,pep);
for(Integer key:pep.keySet()){
System.out.println(pep.get(key));
}
}
}
}
#算法题目求助##腾讯##Java工程师#