Skip to content

Commit ce7db4a

Browse files
committed
codeforces round 542
1 parent 0c8c424 commit ce7db4a

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

Codeforces/Codeforces Round/542/A.cpp

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <iostream>
2+
#include <cmath>
3+
4+
using namespace std;
5+
6+
int cntPos, cntNeg;
7+
int n;
8+
9+
int main()
10+
{
11+
cin >> n;
12+
for(int i = 0; i < n; i++)
13+
{
14+
int num;
15+
cin >> num;
16+
17+
if(num > 0)
18+
cntPos++;
19+
else if(num < 0)
20+
cntNeg++;
21+
}
22+
23+
if(cntPos >= ceil(n / 2.0))
24+
cout << 1 << '\n';
25+
else if(cntNeg >= ceil(n / 2.0))
26+
cout << -1 << '\n';
27+
else
28+
cout << 0 << '\n';
29+
}

Codeforces/Codeforces Round/542/B.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <iostream>
2+
#include <algorithm>
3+
#include <cmath>
4+
5+
using namespace std;
6+
7+
pair<int, int> a[200002];
8+
int n;
9+
long long ans;
10+
11+
int main()
12+
{
13+
cin >> n;
14+
for(int i = 1; i <= n * 2; i++)
15+
{
16+
cin >> a[i].first;
17+
a[i].second = i;
18+
}
19+
20+
sort(a + 1, a + n * 2 + 1);
21+
a[0].second = 1;
22+
23+
ans = abs(a[1].second - 1) + abs(a[2].second - 1);
24+
25+
for(int i = 1; i <= n * 2 - 2; i += 2)
26+
{
27+
int a1 = a[i].second;
28+
int a2 = a[i + 1].second;
29+
int a3 = a[i + 2].second;
30+
int a4 = a[i + 3].second;
31+
32+
long long here = min(abs(a1 - a3) + abs(a2 - a4), abs(a1 - a4) + abs(a2 - a3));
33+
ans += here;
34+
}
35+
36+
cout << ans << '\n';
37+
}

Codeforces/Codeforces Round/542/C.cpp

Whitespace-only changes.

Codeforces/Codeforces Round/542/D.cpp

Whitespace-only changes.

0 commit comments

Comments
 (0)