import java.util.*;
public class Main {
public static void main(String[] args) {
new Main().run();
}
private void run() {
HashMap<Integer,Student> hashMap=new HashMap<Integer,Student>();
ArrayList<Student> arrayList=new ArrayList<Student>();
Scanner input=new Scanner(System.in);
int n,m;
n=input.nextInt();
m=input.nextInt();
for (int i =1; i <=n; i++) {
hashMap.put(i,new Student(i));
}
for (int i = 0; i < m; i++) {
int num=input.nextInt();
int ins=input.nextInt();
int low,high;
Student ptr=hashMap.get(num);
int index=ptr.position;
ptr.position+=ins;
if (ins>0){
low=index+1;
high=index+ins;
for (Integer integer : hashMap.keySet()) {
if(hashMap.get(integer).position>=low&&hashMap.get(integer).position<=high)
hashMap.put(integer,new Student(integer,hashMap.get(integer).position-1));
}
hashMap.put(ptr.id,new Student(ptr.id,ptr.position));
}
else {
low=index+ins;
high=index-1;
for (Integer integer : hashMap.keySet()) {
if(hashMap.get(integer).position>=low&&hashMap.get(integer).position<=high)
hashMap.put(integer,new Student(integer,hashMap.get(integer).position+1));
}
hashMap.put(ptr.id,new Student(ptr.id,ptr.position));
}
}
arrayList.addAll(hashMap.values());
Collections.sort(arrayList, new Comparator<Student>() {
@Override
public int compare(Student o1, Student o2) {
if (o2.position<=o1.position) return 1;
else return -1;
}
});
System.out.print(arrayList.get(0).id);
for (int i = 1; i <arrayList.size() ; i++) {
System.out.print(" "+arrayList.get(i).id);
}
}
class Student{
public int id;
public int position;
public Student(int i){
this.id=i;
this.position=i-1;
}
public Student(int id,int position){
this.id=id;
this.position=position;
}
}
}
ccf 排队问题
最新推荐文章于 2024-12-20 07:47:06 发布
1215

被折叠的 条评论
为什么被折叠?



