-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgameshow2.cpp
More file actions
47 lines (38 loc) · 989 Bytes
/
gameshow2.cpp
File metadata and controls
47 lines (38 loc) · 989 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
45
46
47
// NOTE: it is recommended to use this even if you don't understand the following code.
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
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");
int N;
cin >> N;
int V[N], P[N], C[N];
for(int i=0; i<N; i++)
cin >> V[i];
for(int i=0; i<N; i++)
cin >> P[i];
for(int i=0; i<N; i++)
cin >> C[i];
// insert your code here
int base=0, cont=0, total=0;
for (int i=0; i<N; i++) {
if (V[i]-P[i] > C[i]) {
if (cont >= P[i]) {
cont -= P[i];
} else {
base += (P[i]-cont);
cont =0;
}
total += V[i] - P[i];
} else {
total += C[i];
cont += C[i];
}
}
cout << total << " " << base << endl; // print the result
return 0;
}