-
Notifications
You must be signed in to change notification settings - Fork 0
/
493B.cpp
79 lines (75 loc) · 1.27 KB
/
493B.cpp
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
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
int main()
{
ll n;
cin >> n;
vector < ll > a;
vector < ll > b;
ll totala = 0;
ll totalb = 0;
ll last;
while( n-- )
{
ll x;
cin >> x;
if(x < 0)
{
totalb+=abs(x);
b.push_back(-1 * x);
}
else
{
totala+=abs(x);
a.push_back(x);
}
if( n == 0)
{
last = x;
}
}
if(totala > totalb)
cout << "first" << endl;
else if(totala < totalb)
cout << "second" << endl;
else
{
int i = 0;
int j = 0;
int l = a.size();
int m = b.size();
int f = 0;
while( i < l && j < m)
{
if(b[j] > a[i])
{
f = 1;
break;
}
else if(b[j] < a[i])
break;
i++;
j++;
}
if(i == l && j == m)
{
if(last < 0)
cout << "second" <<endl;
else
cout << "first" << endl;
}
else if(f)
cout << "second" << endl;
else
{
if(i == l)
{
cout << "second" << endl;
}
else
cout << "first" << endl;
}
}
}