-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfish.cpp
More file actions
65 lines (62 loc) · 1.65 KB
/
fish.cpp
File metadata and controls
65 lines (62 loc) · 1.65 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
64
65
// you can use includes, for example:
// #include <algorithm>
#define noop
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A, vector<int> &B) {
// write your code in C++14 (g++ 6.2.0)
int stream = 0;
int fish_size = 0;
//int survived = 0;
vector<int> survived;
for(int x = 0;x < A.size();x++)
{
//cout << "x " << x << endl;
if(survived.size() < 1)
{
if(B[x] == 0)
{
survived.push_back(A[x]);
}
else
{
survived.push_back(-A[x]);
}
}
else
{
if((survived.back() < 0)&&(B[x] == 0))
{
while(survived.back() < 0)
{
//they meet
if((survived.back() + A[x]) < 0)
{
//cout << 1 << " eats" << endl;
goto endloop;
}
else
{
survived.pop_back();
//survived.push_back(A[x]);
}
}
survived.push_back(A[x]);
}
else
{
//cout << "add " << x << endl;
if(B[x] == 0)
{
survived.push_back(A[x]);
}
else
{
survived.push_back(-A[x]);
}
}
}
endloop: noop;
}
return survived.size();
}