#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, cnt = 0;
cin >> n;
vector<pair<int, int>> arr;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
if(x <= 1440) cnt++;
arr.push_back({x, 1});
}
int m;
cin >> m;
for (int i = 1; i <= m; i++) {
int x;
cin >> x;
if (x <= 1440) cnt++;
arr.push_back({x, 2});
}
sort(arr.begin(), arr.end());
vector<pair<int, int>> res(n + m + 5);
res[0] = (arr[0].second == 1 ? pair<int, int>(1, 0) : pair<int, int>(0, 1));
for (int i = 1; i < arr.size(); i++) {
int x = res[i - 1].first, y = res[i - 1].second;
if (arr[i].second == 1) x++;
else y++;
res[i] = {x, y};
}
int cnt2 = 0;
for (int i = 1; i < arr.size() - 1; i++) {
int prev_x = res[i - 1].first, prev_y = res[i - 1].second;
int next_x = res[i + 1].first, next_y = res[i + 1].second;
int x = res[i].first, y = res[i].second;
if (prev_x > prev_y && x == y && next_x < next_y) cnt2++;
else if(prev_x < prev_y && x == y && next_x > next_y) cnt2++;
}
cout << cnt << '\n' << cnt2 << '\n';
return 0;
}
Compilation message
preokret.cpp: In function 'int main()':
preokret.cpp:30:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for (int i = 1; i < arr.size(); i++) {
| ~~^~~~~~~~~~~~
preokret.cpp:37:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for (int i = 1; i < arr.size() - 1; i++) {
| ~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
316 KB |
Output is correct |
9 |
Correct |
1 ms |
324 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |