#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long int
#define vi vector<int>
#define va vector<vector<int>>
#define frr(i,n) for(int i=0;i<n;i++)
#define fir(n,i) for(int i=n-1;i>=0;i--)
using namespace std;
int main(int argc, char* argv[])
{
vi s, g, h, k;
int a, b, c, d, e = 0;
cin >> a >> b;
frr(i, a) {
cin >> c;
if (c < 0) s.push_back(abs(c));
e++;
}
frr(i, b) {
if (c > 0) s.push_back(abs(c));
sort(s.begin(), s.end());
cout << s[(e / 2)-1];
Объяснение:
def run():
a = int(input())
b = int(input())
trains = []
for i in range(a + b):
trains.append(int(input()))
t = 0
s = sum(i if i >= 0 else -i for i in trains)
while True:
for i in range(a):
trains[i] += 1
for i in range(b):
trains[a + i] -= 1
s1 = sum(i if i >= 0 else -i for i in trains)
if s1 < s:
s = s1
t += 1
else:
return t
print(run())
Язык Python, на
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long int
#define vi vector<int>
#define va vector<vector<int>>
#define frr(i,n) for(int i=0;i<n;i++)
#define fir(n,i) for(int i=n-1;i>=0;i--)
using namespace std;
int main(int argc, char* argv[])
{
vi s, g, h, k;
int a, b, c, d, e = 0;
cin >> a >> b;
frr(i, a) {
cin >> c;
if (c < 0) s.push_back(abs(c));
e++;
}
frr(i, b) {
cin >> c;
if (c > 0) s.push_back(abs(c));
e++;
}
sort(s.begin(), s.end());
cout << s[(e / 2)-1];
}
Объяснение:
def run():
a = int(input())
b = int(input())
trains = []
for i in range(a + b):
trains.append(int(input()))
t = 0
s = sum(i if i >= 0 else -i for i in trains)
while True:
for i in range(a):
trains[i] += 1
for i in range(b):
trains[a + i] -= 1
s1 = sum(i if i >= 0 else -i for i in trains)
if s1 < s:
s = s1
t += 1
else:
return t
print(run())
Объяснение:
Язык Python, на