forked from Dishakumra/Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjobsequence.java
81 lines (76 loc) · 1.42 KB
/
jobsequence.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import java.util.*;
//import static testing.Sorting.swap;
class jobsequence
{
public static void swap(int arr[],int i,int j)
{
int temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
public static void swap(String arr[],int i,int j)
{
String temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int jobs=sc.nextInt();
String h=sc.nextLine();
String name[]=new String[jobs];
int p[]=new int[jobs];
int dead[]=new int[jobs];
int max=0;
for(int i=0;i<jobs;i++)
{
name[i]=sc.nextLine();
}
for(int i=0;i<jobs;i++)
{
p[i]=sc.nextInt();
}
for(int i=0;i<jobs;i++)
{
dead[i]=sc.nextInt();
if(dead[i]>max)
max=dead[i];
}
for(int i=0;i<jobs;i++)
{
for(int j=0;j<jobs-1;j++)
{
if(p[j]<p[j+1])
{
swap(name,j,j+1);
swap(p,j,j+1);
swap(dead,j,j+1);
}
}
}
// for(int g=0;g<jobs;g++)
// {
// System.out.print(name[g]+" ");
// }
String arr[]=new String[max];
for(int k=0;k<max;k++)
arr[k]="$$";
for(int i=0;i<jobs;i++)
{
for(int j=dead[i]-1;j>=0;j--)
{
String f="$$";
if(arr[j].equals(f))
{
arr[j]=name[i];
break;
}
}
}
for(int i=0;i<max;i++)
{
System.out.println(arr[i]);
}
}
}