-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstocks.cpp
More file actions
66 lines (56 loc) · 1.13 KB
/
stocks.cpp
File metadata and controls
66 lines (56 loc) · 1.13 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
66
// NOTE: it is recommended to use this even if you don't understand the following code.
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
// input data
long long N;
vector<long long> V, S;
int main() {
// uncomment the following lines if you want to read/write from files
ifstream cin("input.txt");
ofstream cout("output.txt");
cin >> N;
V.resize(N);
S.resize(N);
for (long long i=0; i<N; i++)
cin >> V[i];
for (long long i=0; i<N; i++)
cin >> S[i];
// insert your code here
long long sum = 0;
for (long long i=0; i<N; i++) {
bool good = false, nuovo = true;
long long temp;
if (i==0 && S[0] == 1) {
temp = V[0];
if (N>=2) {
i++;
}
good = true;
} else {
temp = 0;
}
while (S[i] == 1) {
if (V[i] >= V[i-1] || nuovo) {
temp += V[i];
good = true;
nuovo = false;
if (i < N-1) {
i++;
} else {
break;
}
} else {
i--;
break;
}
}
if (temp > sum && good) {
sum = temp;
}
}
cout << sum << endl; // print the result
return 0;
}