-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfish.cpp
More file actions
37 lines (31 loc) · 729 Bytes
/
fish.cpp
File metadata and controls
37 lines (31 loc) · 729 Bytes
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
#include <iostream>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
int solution(vector<int> &A, vector<int> &B) {
stack<int> s;
for (int i = 0; i < A.size(); i++) {
if (s.empty() || B[i] == 1 || B[i] == B[s.top()])
s.push(i);
else {
// B[i] == 0
// s not empty
// B[i] != B[s.top()]
// -> B[s.top()] == 1
// if (A[s.top()] > A[i]) continue;
while (!s.empty() && B[s.top()] == 1 && A[i] > A[s.top()]) {
s.pop();
}
if (s.empty() || B[s.top()] == 0) {
s.push(i);
}
}
}
return s.size();
}
int main() { return 0; }
/**
* Submission link:
* https://app.codility.com/demo/results/trainingUKT22H-HZP/
*/