-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgasoline.cpp
More file actions
44 lines (38 loc) · 735 Bytes
/
gasoline.cpp
File metadata and controls
44 lines (38 loc) · 735 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
38
39
40
41
42
43
44
#include <iostream>
#include <fstream>
using namespace std;
int main() {
// uncomment the following lines if you want to read/write from files
// ifstream cin("input.txt");
// ofstream cout("output.txt");
long long N;
cin >> N;
int P[N], G[N];
for (long long i=0; i<N; i++) {
cin >> P[i];
}
for (long long i=0; i<N; i++) {
cin >> G[i];
}
// insert your code here
long long litres, temp, ans=0;
for (long long i=0; i<N; i++) {
litres=G[i];
temp = P[i];
if (i != N-1) {
while (temp < P[i+1]) {
if (i != N-1) {
i ++;
} else {
break;
}
litres += G[i];
}
ans += temp * litres;
} else {
ans += temp * G[i];
}
}
cout << ans << endl; // print the result
return 0;
}