-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.java
105 lines (83 loc) · 2.57 KB
/
Game.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Codechef Link : https://www.codechef.com/LTIME57/problems/GAMENUMB
import java.util.*;
class Game
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
int i,j,N,K,C = 0;
if(T<1 || T>100)
return;
for (i = 0; i < T; i++)
{
N = sc.nextInt();
K = sc.nextInt();
int A[] = new int[N];
int D[] = new int[N];
for(j = 0; j < N; j++)
{
A[j] = sc.nextInt();
}
for(j = 0; j < N; j++)
{
D[j] = sc.nextInt();
C = C + D[j];
}
int array[] = new int[C];
for(j = 0; j < N; j++)
{
for(int k = 0; k < D[j]; k++)
{
array[k] = A[j];
System.out.print(array[k]+" ");
}
}
for(j = 0; j < N; j++)
{
for(k = j+1; k < N; k++)
{
if(array[j] > array[k])
{
temp = array[j];
array[j] = array[k];
array[k] = temp;
}
}
}
for(j = 0; j < K; j++)
{
B[j] = sc.nextInt();
}
// this part need to be debugged
for(j = 0; j < K; j++)
{
if(j%2!=0)
{
for(k = C - B[j] ; k < C ; k++)
{
newArray[l] = array[k];
l++;
}
// struck here
for(k = 0 ; k < B[j] ; k++)
{
array[k] = newArray[k];
}
C = B[j];
}
else
{
for(k = 0 ; k < B[j] ; k++)
{
array[k] = newArray[k];
}
C = B[j];
}
}
}
for(i = 0; i < C; i++)
s += array[k];
sc.close();
}
}