-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2879.cpp
More file actions
49 lines (39 loc) ยท 829 Bytes
/
2879.cpp
File metadata and controls
49 lines (39 loc) ยท 829 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
48
49
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int N; cin >> N;
vector<int> arr(N + 1, 0);
for (int i = 0; i < N; i++)
cin >> arr[i];
for (int i = 0; i < N; i++) {
int num;
cin >> num;
arr[i] -= num;
}
int ans = 0;
bool bIsChecked = true;
while (bIsChecked)
{
bIsChecked = false;
for (int i = 0; i < N; i++) {
if (arr[i] == 0) continue;
bIsChecked = true;
int minValue = arr[i];
for (int j = i + 1; j <= N; j++) {
if (arr[i] * arr[j] > 0) {
minValue = abs(arr[j]) < abs(arr[i]) ? arr[j] : arr[i];
}
else {
ans += abs(minValue);
for (int k = i;k < j;k++) arr[k] -= minValue;
i = j - 1;
break;
}
}
}
}
cout << ans << " ";
return 0;
}