This repository was archived by the owner on Jun 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathB_arjavgarg.c
More file actions
63 lines (59 loc) · 1.23 KB
/
B_arjavgarg.c
File metadata and controls
63 lines (59 loc) · 1.23 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main() {
int n, a, b;
scanf("%d %d %d", &n, &a, &b);
int positions[n];
int strengths[n];
int i;
for(i = 0; i < n; i++) {
int x;
scanf("%d", &x);
positions[i] = i+1;
strengths[i] = x;
}
int leftover = n;
while(leftover > 1) {
int j = -1;
for(i = 0; i < n; i++) {
int r1 = strengths[i];
int p1 = positions[i];
i++;
if(i == n) {
strengths[i-1] += b;
strengths[leftover-1] = strengths[i-1];
positions[leftover-1] = positions[i-1];
positions[i-1] = strengths[i-1] = -1;
}
else {
int r2 = strengths[i];
int p2 = positions[i];
if(r1 > r2) {
positions[i-1] = strengths[i-1] = positions[i] = strengths[i] = -1;
strengths[++j] = abs(r1 - a*(r1-r2));
positions[j] = p1;
leftover--;
}
else if(r1 == r2) {
leftover -= 2;
positions[i-1] = strengths[i-1] = positions[i] = strengths[i] = -1;
}
else {
positions[i-1] = strengths[i-1] = positions[i] = strengths[i] = -1;
strengths[++j] = abs(r2 - a*(r2-r1));
positions[j] = p2;
leftover--;
}
}
}
n = leftover;
}
if(leftover) {
printf("%d %d", positions[0], strengths[0]);
}
else {
printf("-1 -1");
}
return 0;
}