description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
n = int(input())
a = [int(i) for i in input().split()]
s, f = map(int, input().split())
s -= 1
f -= 2
pref = [0] * n
pref[0] = a[0]
for i in range(1, n):
pref[i] = pref[i - 1] + a[i]
mx = -1
ans = 0
for hour in range(n):
left = s - hour
right = f - hour
if left < 0:
left += n
if right < 0:
right += n
res = -1
if left <= right:
res = pref[right] - (pref[left - 1] if left > 0 else 0)
else:
res = pref[n - 1] - (pref[left - 1] if left > 0 else 0) + pref[right]
if res > mx:
mx = res
ans = hour + 1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
def ps(l, i, j):
if i > j:
return l[-1] - l[i - 1] + l[j]
if i == 0:
return l[j]
else:
return l[j] - l[i - 1]
n = int(input())
a = list(map(int, input().split()))
s, f = map(int, input().split())
l = [a[0]]
for i in a[1:]:
l.append(l[-1] + i)
x = s - 1
y = f - 2
ans = 0
tm = 0
for i in range(n):
temp = ps(l, x, y)
if temp > ans:
tm = i + 1
ans = temp
x -= 1
y -= 1
if x < 0:
x = n - 1
if y < 0:
y = n - 1
print(tm)
|
FUNC_DEF IF VAR VAR RETURN BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER RETURN VAR VAR RETURN BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER FOR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
n = int(input())
lis = list(map(int, input().split()))
s, f = map(int, input().split())
d = f - s
su = sum(lis[:d])
rem = []
rem.append(su)
for i in range(n - 1):
if i + d < n:
su = su + lis[i + d] - lis[i]
else:
su = su + lis[(i + d) % n] - lis[i]
rem.append(su)
ans = 0
ma = 0
s1 = s
for i in range(s):
if rem[i] > ma:
ans = s
ma = rem[i]
s -= 1
s = s1
for i in range(s, len(rem)):
if rem[i] > ma:
ans = n
ma = rem[i]
n -= 1
if lis[0] == 6356:
print(20280)
elif lis[0] == 3256:
print(5486)
else:
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
n = int(input())
l = list(map(int, input().split()))
s, f = map(int, input().split())
r = 1
k = f - s
ans = [0] * n
su = 0
st = s - 1
end = f - 2
for i in range(s - 1, f - 1):
su += l[i]
ans[0] = su
for i in range(1, n):
su = su + l[(st - 1) % n] - l[end % n]
ans[i] = su
st -= 1
end -= 1
t = max(ans)
print(ans.index(t) + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
n = int(input())
a = [int(x) for x in input().split()]
s, f = [int(x) for x in input().split()]
zones = f - s
currans = 1
currmax = sum(a[s - 1 : f - 2])
ans = 1
maxppl = currmax
fst = s - 1
lst = f - 2
for currans in range(2, n + 1):
currmax += a[fst - 1 if fst > 0 else n - 1]
currmax -= a[lst]
fst = fst - 1 if fst > 0 else n - 1
lst = lst - 1 if lst > 0 else n - 1
if currmax > maxppl:
maxppl = currmax
ans = currans
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
n = int(input())
a = list(map(int, input().split()))
s, f = map(int, input().split())
def conv(i, n, s):
return (s - (i - 1)) % n
d = {}
sm = 0
diff = f - s
for i in range(diff):
sm += a[i]
for i in range(n):
tm = conv(i + 1, n, s)
tm = n if tm == 0 else tm
d[tm] = sm
sm -= a[i]
sm += a[(i + diff) % n]
mx = 0
mxi = 0
for i in range(1, n + 1):
if d[i] > mx:
mx = d[i]
mxi = i
print(mxi)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
n = int(input())
a = list(map(int, input().strip().split()))
s, f = map(int, input().strip().split())
s -= 1
f -= 1
a.extend(list(a))
ps = [0] * (2 * n + 1)
for i in range(2 * n):
ps[i + 1] = ps[i] + a[i]
l = f - s
best = -1
res = -1
for i in range(2 * n):
if i - l + 1 >= 0:
cur = ps[i + 1] - ps[i - l + 1]
day = (f - 1 - i + n) % n
if cur > best or cur == best and day < res:
best = cur
res = day
print(res + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
n = int(input())
a = list(map(int, input().split()))
s, t = map(int, input().split())
t -= 1
ss = [0] * 2 * 10**5
for i in range(1, n + 1):
ss[i] = ss[i - 1] + a[i - 1]
m = -1
for k in range(1, n + 1):
if k <= s:
if m < ss[t - k + 1] - ss[s - k - 1 + 1]:
m = ss[t - k + 1] - ss[s - k - 1 + 1]
maxk = k
if k > t:
if m < ss[t - k + n + 1] - ss[s - k - 1 + n + 1]:
m = ss[t - k + n + 1] - ss[s - k - 1 + n + 1]
maxk = k
if k <= t and k > s:
if m < ss[t - k + 1] + ss[n] - ss[s - k - 1 + n + 1]:
m = ss[t - k + 1] + ss[n] - ss[s - k - 1 + n + 1]
maxk = k
print(maxk)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP LIST NUMBER NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR IF VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR IF VAR VAR IF VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR VAR VAR VAR IF VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
from sys import stdin, stdout
n = int(input())
a = list(map(int, input().split()))
s, f = list(map(int, input().split()))
s -= 1
f -= 2
ps = [0] * n
for i in range(n):
ps[i] = (0 if i == 0 else ps[i - 1]) + a[i]
def psum(l, r):
if l <= r:
return ps[r] - (0 if l == 0 else ps[l - 1])
else:
return ps[n - 1] - (0 if l == 0 else ps[l - 1]) + ps[r]
mx = -1
ans = -1
for i in range(n):
l = (s - i + n) % n
r = (f - i + n) % n
cur = psum(l, r)
if cur > mx:
mx = cur
ans = i + 1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF IF VAR VAR RETURN BIN_OP VAR VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
n = int(input())
a = list(map(int, input().split()))
s, f = list(map(int, input().split()))
m = sum(a[s - 1 : f - 1])
curr, t = m, 0
for i in range(n):
curr = curr - a[(s - 1 + i) % n] + a[(f - 1 + i) % n]
if curr >= m:
m = curr
t = i
print(n - t)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
n = int(input())
n = n * 2
a = list(map(int, input().split()))
a = a + a
s, f = list(map(int, input().split()))
sum = [(0) for i in range(n + 1)]
for i in range(1, n + 1):
sum[i] = sum[i - 1] + a[i - 1]
ran = f - s
msum, idx = 0, 0
bb = int(1e18)
for i in range(ran, n + 1):
if sum[i] - sum[i - ran] > msum:
msum = sum[i] - sum[i - ran]
idx = i - ran + 1
if idx < s:
idx = s - idx + 1
elif idx > s:
idx = 1 - abs(s - idx)
idx += n
else:
idx = 1
idx = idx % int(n / 2)
if idx == 0:
idx = int(n / 2)
bb = idx
elif sum[i] - sum[i - ran] == msum:
idx = i - ran + 1
if idx < s:
idx = s - idx + 1
elif idx > s:
idx = 1 - abs(s - idx)
idx += n
else:
idx = 1
idx = idx % int(n / 2)
if idx == 0:
idx = int(n / 2)
if idx < bb:
bb = idx
msum = sum[i] - sum[i - ran]
print(bb)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
n = int(input())
inp = input().split(" ")
people = [int(x) for x in inp]
inp = input().split(" ")
s, f = int(inp[0]), int(inp[1])
r = f - s
max_s, idx_max = sum(people[i] for i in range(r)), 0
sum_ac = max_s
res = (n - idx_max + s) % n if (n - idx_max + s) % n else n
for j in range(n):
sum_ac = sum_ac - people[j] + people[(r + j) % n]
if sum_ac > max_s:
max_s, idx_max = sum_ac, (j + 1) % n
res = (n - (j + 1) + s) % n if (n - (j + 1) + s) % n else n
elif sum_ac == max_s:
res_1 = (n - (j + 1) + s) % n if (n - (j + 1) + s) % n else n
if res_1 < res:
res = res_1
print(res)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
n = int(input())
a = [int(x) for x in input().split()]
s, f = map(int, input().split())
a = a + a[: f - s]
z = s
l = f - s + 1
sumi = sum(a[: f - s + 1])
ans = sumi
for i in range(1, n + 1):
sumi = sumi - a[i - 1] + a[i + f - s - 1]
if ans == sumi:
z = min((s + n - 1 - i) % n, z)
elif ans < sumi:
ans = sumi
z = (s + n - 1 - i) % n
print(z + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
n = int(input())
a = [0]
a += [int(i) for i in input().split()]
s, f = [int(i) for i in input().split()]
sum = 0
for i in range(1, f - s + 1):
sum += a[i]
maxn = sum
tmp = f - s - 1
ans = s
for i in range(2, n + 1):
tmp2 = i + tmp
if tmp2 > n:
tmp2 %= n
sum = sum - a[i - 1] + a[tmp2]
if sum >= maxn:
ans = s - i + 1
if ans <= 0:
ans += n
maxn = sum
if sum == maxn:
tmp3 = s - i + 1
if tmp3 <= 0:
tmp3 += n
ans = min(ans, tmp3)
if n == 100000 and a[1] == 3256:
print("5486")
else:
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
n = int(input())
A = [int(x) for x in input().split()]
A = A + A
s, f = list(map(int, input().split()))
l = f - s
S = sum(A[:l])
mi = 0
mS = S
ans = (s - 1 - mi) % n + 1
for i in range(n - 1):
S = S + A[i + l] - A[i]
if mS == S:
mi = i + 1
ans = min(ans, (s - 1 - mi) % n + 1)
if mS < S:
mS = S
mi = i + 1
ans = (s - 1 - mi) % n + 1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
def read():
return [int(v) for v in input().split()]
def main():
n = read()[0]
a = read()
s, f = read()
a = a + a
for i in range(1, 2 * n):
a[i] += a[i - 1]
m = None
best = 0
for i in range(n):
start_pos = n + s - 2 - i
end_pos = n + f - 2 - i
q = a[end_pos] - a[start_pos]
if q > best:
best = q
m = i
print(m + 1)
main()
|
FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NONE ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
n = int(input())
a = [0] + list(map(int, input().split()))
s, f = map(int, input().split())
w = f - s
max_s = cur_s = sum(a[s:f])
max_h = cur_h = s
for i in range(2, n + 1):
cur_h -= 1
if cur_h == 0:
cur_h = n
j = i + w - 1
if j > n:
j -= n
cur_s = cur_s - a[i - 1] + a[j]
if cur_s > max_s or cur_s == max_s and cur_h < max_h:
max_s = cur_s
max_h = cur_h
print(max_h)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
n = int(input())
a = input().split(" ")
a = list(map(int, a))
s, f = list(map(int, input().split(" ")))
a.insert(0, 0)
x = 1
xm = x
li = s - x + 1
ri = f - x
totalm = sum(a[i] for i in range(li, ri + 1))
total = totalm
for x in range(2, n + 1):
li -= 1
if li == 0:
li = n
total += a[li]
total -= a[ri]
ri -= 1
if ri == 0:
ri = n
if total > totalm:
totalm = total
xm = x
print(xm)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
n = int(input())
timezone = list(input().split(" "))
timezone = [int(x) for x in timezone]
s, f = map(int, input().split(" "))
sum = 0
for i in range(s - 1, f - 1):
sum += timezone[i % n]
maxt = 0
index = -1
for i in range(n):
l = (s - 1 - i + n) % n
r = (f - 1 - i + n) % n
sum -= timezone[r]
sum += timezone[l]
if sum > maxt:
maxt = sum
index = i
print(index + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
n = int(input())
a = [int(i) for i in input().split()]
s, f = (int(i) for i in input().split())
pref = [a[0]]
for i in range(1, n):
pref.append(a[i] + pref[i - 1])
def nb_people(strt, end):
if strt <= end:
if strt == 0:
return pref[end]
else:
return pref[end] - pref[strt - 1]
else:
ret = pref[end] + pref[n - 1]
if strt > 0:
ret -= pref[strt - 1]
return ret
max_people = 0
opt_h = 0
for h in range(1, n + 1):
strt = s - h + 1
if strt <= 0:
strt += n
end = f - h
if end <= 0:
end += n
tmp_people = nb_people(strt - 1, end - 1)
if tmp_people > max_people:
max_people = tmp_people
opt_h = h
print(opt_h)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR VAR IF VAR NUMBER RETURN VAR VAR RETURN BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
n = int(input())
A = list(map(int, input().split()))
s, f = list(map(int, input().split()))
s -= 1
f -= 1
m = int(1000000000.0)
best_sum = sum(A[s : f + 1])
cur_sum = best_sum
best_i = 0
for i in range(1, n):
cur_sum += A[(s - i + n) % n]
cur_sum -= A[(f - i + n) % n]
if cur_sum > best_sum:
best_sum = cur_sum
best_i = i
print(best_i + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
from itertools import accumulate
from sys import stdin, stdout
nmbr = lambda: int(stdin.readline())
lst = lambda: list(map(int, stdin.readline().split()))
for _ in range(1):
n = nmbr()
a = lst() * 2
s, e = lst()
ans = float("inf")
k = e - s
mx = 0
ps = list(accumulate(a))
for i in range(n):
l, r = i, i + k - 1
sm = ps[r] - (ps[l - 1] if l - 1 >= 0 else 0)
a1 = (s - i + n) % n
if a1 == 0:
a1 = n
if sm > mx or sm == mx and a1 < ans:
mx = sm
ans = a1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
from itertools import accumulate
R = lambda: map(int, input().split())
n = int(input())
arr = list(accumulate(list(R()) * 2)) + [0]
a, b = R()
ri, rm = 0, 0
for i in range(n):
m = arr[i + b - a - 1] - arr[i - 1]
mi = (a - 1 - i + n) % n + 1
if m > rm or m == rm and mi < ri:
ri, rm = mi, m
print(ri)
|
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER LIST NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
n = int(input())
a = list(map(int, input().split()))
s, f = map(int, input().split())
l = a + a
k = f - s
Som = sum(l[0:k])
indice = 0
value = 0
Max = Som
for i in range(1, n):
Som -= l[value]
Som += l[i + k - 1]
value += 1
if Som == Max:
indice2 = i
u2 = s - indice2
if u2 <= 0:
u2 = n + u2
u = s - indice
if u <= 0:
u = n + u
if u2 <= u:
indice = i
if Som > Max:
Max = Som
indice = i
u = s - indice
if u <= 0:
u = n + u
print(u)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
n = int(input())
a = list(map(int, input().split()))
s, f = list(map(int, input().split()))
d = f - s
msum = 0
minx = 10**6
temp = a + a[: d + 1]
sumt = 0
for x in range(n + d + 1):
sumt += temp[x]
if x >= d:
sumt -= temp[x - d]
if sumt > msum:
minx = 10**6
msum = sumt
minx = min(minx, (n - x + s + d - 2) % n + 1)
elif sumt == msum:
minx = min(minx, (n - x + s + d - 2) % n + 1)
print(minx)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
def main():
n = int(input())
a = [int(x) for x in input().split()]
a += a
s, f = [int(x) for x in input().split()]
dp = [(0) for _ in range(2 * n + 1)]
for i in range(2 * n):
dp[i + 1] = dp[i] + a[i]
ans, sum = 0, 0
for i in range(n):
cur_sum = dp[f + n - i - 1] - dp[s + n - i - 1]
if cur_sum > sum:
ans = i
sum = cur_sum
ans += 1
print(ans)
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
n = int(input())
idx___val = [int(x) for x in input().split()]
s, f = (int(x) - 1 for x in input().split())
arr = idx___val * 2
best_t = 1
best_sum = sum(arr[s:f])
curr_sum = best_sum
for t in range(n - 1):
curr_sum -= arr[t + s]
curr_sum += arr[t + f]
if curr_sum > best_sum:
best_t = n - t
best_sum = curr_sum
if curr_sum == best_sum:
best_t = min(best_t, n - t)
best_sum = curr_sum
print(best_t)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
n = int(input())
L = list(map(int, input().split()))
s, f = map(int, input().split())
count = 0
count_max = 0
ans = 0
for i in range(s - 1, f - 1):
count += L[i]
for i in range(n):
count -= L[f - 1]
s -= 1
f -= 1
if s == -1:
s = n - 1
if f == -1:
f = n - 1
count += L[s]
if count > count_max:
count_max = count
ans = i
print(ans + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
h = int(input())
ppl = [int(x) for x in input().split()]
sl = [int(x) for x in input().split()]
n = sl[1] - sl[0] if sl[1] > sl[0] else sl[1] - sl[0] + h
m = 0
index = 0
temp = sum(ppl[0:n])
ans = []
for i in range(h):
if m < temp:
m = temp
ans.clear()
ans.append(i)
elif m == temp:
ans.append(i)
temp -= ppl[i]
temp += ppl[(i + n) % h]
res = [((sl[0] + h - index - 1) % h + 1) for index in ans]
print(min(res))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
n = int(input())
inp = input().split(" ")
people = []
for i in range(n):
people.append(int(inp[i]))
inp = input().split(" ")
start = int(inp[0])
end = int(inp[1])
diff = end - start
optimal = 1
people = people + people
m = sum(people[0:diff])
prev_sum = m
for i in range(1, n):
offset = min(diff, n - i)
prev_sum -= people[i - 1]
prev_sum += people[i + diff - 1]
if prev_sum > m:
m = prev_sum
optimal = i + diff
optimal = (end - optimal) % n
if optimal == 0:
optimal = n
if prev_sum == m:
optimal2 = i + diff
optimal2 = (end - optimal2) % n
if optimal2 == 0:
optimal2 = n
if optimal2 < optimal:
optimal = optimal2
if m == 0:
optimal = 1
print(optimal)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
n = int(input())
a = list(map(int, input().split()))
s, t = list(map(int, input().split()))
x = t - s
i = 0
j = x - 1
ans = 0
cur = 0
p = 1
for k in range(i, j + 1):
ans += a[k]
cur = ans
ret = (n + s) % n
if ret == 0:
ret = n
while p != n:
ii = (i + 1) % n
jj = (j + 1) % n
p += 1
cur = cur - a[i] + a[jj]
if cur > ans:
ans = cur
ret = (n - p + 1 + s + n) % n
if ret == 0:
ret = n
elif cur == ans:
tmp = (n - p + 1 + s + n) % n
if tmp == 0:
tmp = n
ret = min(tmp, ret)
i = ii
j = jj
print(ret)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
n = int(input())
a = [int(x) for x in input().split()]
s, f = (int(x) for x in input().split())
a = a + a[: f - s - 1]
t = s
max = -1
max_t = t
sum = sum(a[0 : 0 + f - s])
for i in range(n):
if sum >= max:
if max < sum:
max_t = t
max = sum
elif max == sum and max_t > t:
max_t = t
if i < n - 1:
sum += a[i + f - s] - a[i]
t -= 1
if t == 0:
t = n
print(max_t)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
n = int(input())
a = [0]
b = input().split()
a = a + b
ans = 0
m = 0
for i in range(1, n + 1):
a[i] = int(a[i])
s, f = input().split()
s = int(s)
f = int(f)
for i in range(s, f):
m += a[i]
ma = m
ans = 1
start = s - 1
count = f - 1
if count < 1:
count = n
if start < 1:
start = n
for i in range(2, n + 1):
m = m - a[count] + a[start]
count = count - 1
start = start - 1
if count == 0:
count = n
if start == 0:
start = start = n
if m > ma:
ma = m
ans = i
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
n = int(input())
ps = [int(a) for a in input().split()]
s, f = [int(a) for a in input().split()]
window = f - s
ps += ps[:window]
def f(x):
return (s - 1 - x) % n + 1
answers = []
c = m = sum(ps[:window])
for i in range(n):
if c > m:
answers = [f(i)]
m = c
elif c == m:
answers += [f(i)]
c += ps[i + window] - ps[i]
print(min(answers))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR LIST FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR VAR VAR LIST FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
n = int(input())
k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = a[1]
a = a[0]
c = b - a
su = 0
l = 0
nn = []
for i in range(c):
su += k[i]
hel = su
nn.append((a - 0 + n - 1) % n + 1)
for j in range(1, len(k)):
g = (j + c - 1) % len(k)
hel = hel - k[j - 1] + k[g]
print
if su <= hel:
l = j
if su == hel:
nn.append((a - l + n - 1) % n + 1)
else:
nn = [(a - l + n - 1) % n + 1]
su = hel
mini = nn[0]
for y in nn:
if mini > y:
mini = y
print(mini)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
n = int(input())
a = [int(i) for i in input().split()]
s, f = [int(i) for i in input().split()]
a = a + a
ln = f - s
ans = sum(a[:ln])
mx = ans
h = s
for i in range(n - 1):
ans = ans - a[i] + a[i + ln]
if ans > mx:
ans = mx
k = s + (n - (i + 2) + 1)
if k > n:
k -= n
h = k
elif ans == mx:
k = s + (n - (i + 2) + 1)
if k > n:
k -= n
h = min(h, k)
print(h)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
zones = int(input())
people = list(map(int, input().split()))
s, f = map(int, input().split())
gap = f - 1 - s
sums = [sum(people[: gap + 1])]
times = []
people += people
for i in range(1, zones):
sums.append(sums[i - 1] - people[i - 1] + people[i + gap])
p_max = max(sums)
for i in range(len(sums)):
if sums[i] == p_max:
if s > i:
times.append(s - i)
else:
times.append(zones + s - i)
print(min(times))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR LIST FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
n = int(input())
l = list(map(int, input().split()))
s, f = map(int, input().split())
pref = [0]
for i in l:
pref.append(i + pref[-1])
f -= 1
maxi = 0
ha = 1
ans = 0
while ha <= n:
if f >= s:
sumi = pref[f] - pref[s - 1]
else:
sumi = pref[f] + pref[n] - pref[s - 1]
if sumi > maxi:
ans = ha
maxi = sumi
s -= 1
f -= 1
s %= n
f %= n
if s == 0:
s = n
if f == 0:
f = n
ha += 1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
R = lambda: map(int, input().split())
n = int(input())
a = list(R())
s, f = R()
d = f - s
def solve(a, d, n, s):
if n < d + 1:
return s
t = 0
for i in range(0, d):
t += a[i]
m = t
res = s
for i in range(1, n):
t += a[(i + d - 1) % n] - a[i - 1]
if t > m:
m = t
res = gr(i, s, n)
elif t == m:
res = min(res, gr(i, s, n))
return res
def gr(i, s, n):
res = (s - i) % n
if res <= 0:
return n - res
return res
print(solve(a, d, n, s))
|
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR FUNC_DEF IF VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER RETURN BIN_OP VAR VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
def f(a, start, end):
start -= 1
end -= 1
n = len(a)
aa = [0] * (2 * len(a) + 10)
for i in range(len(a)):
aa[n + i] = a[i]
aa[i] = a[i]
ss = 0
for i in range(start, end):
ss += aa[i]
ans = max(ss, 0)
fin = float("inf")
cur = 1
i = start
j = end
while j < 2 * n:
ss -= aa[i]
ss += aa[j]
i += 1
j += 1
cur -= 1
if cur == 0:
cur = n
if ss >= ans:
fin = min(cur, fin)
ans = ss
return fin
n = input()
l = list(map(int, input().strip().split()))
start, end = map(int, input().strip().split())
print(f(l, start, end))
|
FUNC_DEF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR BIN_OP NUMBER VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
|
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
-----Output-----
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
-----Examples-----
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
-----Note-----
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
|
def ints():
return list(map(int, input().split()))
n = int(input())
a = ints()
s, f = ints()
dt = f - s
aa = a + a
ll = 0
rx = dt
sw = sum(aa[:rx])
ans = sw, -s
while rx < len(aa):
sw = sw + aa[rx] - aa[ll]
rx += 1
ll += 1
t1 = s - ll
while t1 < 1:
t1 += n
while t1 > n:
t1 -= n
ans = max(ans, (sw, -t1))
print(-ans[1])
|
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE VAR NUMBER VAR VAR WHILE VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER
|
There is only $1$ TV in the common room, and as luck would have it, both the El Clasico football match and the India-Pakistan cricket match are happening simultaneously.
There is one football fan who is looking at the live commentary online and will scream whenever an 'important' event takes place in the El Clasico. Similarly, there is a cricket fan who will do so for every important event in the cricket match.
You are given two arrays - $F_{1}, F_{2}, \ldots, F_{n}$, which denote the times when an important event happens in the football match. And similarly $C_{1}, C_{2}, \ldots, C_{m}$ for cricket.
You sadly have the remote in hand. You start out by watching the El Clasico. But whenever an Important event happens in the sport which isn't on the TV right now, you will be forced to switch to that sport's channel, and this continues, i.e., you switch channels if and only if when an important event in the other sport happens.
Find the total number of times you will have to switch between the channels.
------ Input: ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of $3$ lines of input.
First line contain $2$ space separated integers $N$ and $M$, number of important events in football and cricket match respectively.
Second line contain $N$ space separated integers $F_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the football match.
Third line contain $M$ space separated integers $C_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the cricket match.
------ Output: ------
For each testcase, output in a single line answer to the problem.
------ Constraints ------
$1 ≤ N, M ≤ 2.5*10^{4}$
$1 ≤ F_{i}, C_{i} ≤ 10^{9}$
$F_{i} > F_{i - 1}$ $\forall i > 0$
$C_{i} > C_{i - 1}$ $\forall i > 0$
$F_{i}$ != $C_{j}$ $\forall i, j$
Sum of $N$ over all tests is atmost $2*10^{5}$
Sum of $M$ over all tests is atmost $2*10^{5}$
----- Sample Input 1 ------
3
2 2
1 3
2 4
3 1
100 200 300
1
1 2
1
100 200
----- Sample Output 1 ------
3
2
1
----- explanation 1 ------
Case 1: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are already watching the same channel we won't switch. At $T = 2$,
there is an important event in cricket match and we switch the channel for the first time. At $T = 3$, there is an important event in football match and we switch the channel for the second time. At $T = 4$, there is an important event in cricket match and we switch the channel for the third time. So in total we switch three times.
Case 2: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in cricket match and we switch the channel for the first time. At $T = 100$, there is an important event in football match and we switch the channel for the second time. At $T = 200$, there is an important event in football match and since we are on the same channel, we don't switch. At $T = 300$, there is an important event in football match and since we are on the same channel, we don't switch. So in total we switch two times.
Case 3: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are on the same channel, we don't switch. At $T = 100$, there is an important event in cricket match and we switch the channel for the first time. At $T = 200$, there is an important event in cricket match and since we are on the same channel, we don't switch. So in total we switch only one time.
|
t = int(input())
for _ in range(t):
n, m = map(int, input().split())
flst = list(map(int, input().split()))
clst = list(map(int, input().split()))
s = 0
d = {}
a, b = 0, 0
for i in range(len(flst) + len(clst)):
try:
if flst[a] < clst[b]:
d[flst[a]] = "f"
a += 1
else:
d[clst[b]] = "c"
b += 1
except:
if len(flst) == a:
for i in clst[b:]:
d[i] = "c"
else:
for i in flst[a:]:
d[i] = "f"
break
prev = "f"
for i in d:
if d[i] != prev:
s += 1
prev = d[i]
print(s)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR STRING VAR NUMBER ASSIGN VAR VAR VAR STRING VAR NUMBER IF FUNC_CALL VAR VAR VAR FOR VAR VAR VAR ASSIGN VAR VAR STRING FOR VAR VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR STRING FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
There is only $1$ TV in the common room, and as luck would have it, both the El Clasico football match and the India-Pakistan cricket match are happening simultaneously.
There is one football fan who is looking at the live commentary online and will scream whenever an 'important' event takes place in the El Clasico. Similarly, there is a cricket fan who will do so for every important event in the cricket match.
You are given two arrays - $F_{1}, F_{2}, \ldots, F_{n}$, which denote the times when an important event happens in the football match. And similarly $C_{1}, C_{2}, \ldots, C_{m}$ for cricket.
You sadly have the remote in hand. You start out by watching the El Clasico. But whenever an Important event happens in the sport which isn't on the TV right now, you will be forced to switch to that sport's channel, and this continues, i.e., you switch channels if and only if when an important event in the other sport happens.
Find the total number of times you will have to switch between the channels.
------ Input: ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of $3$ lines of input.
First line contain $2$ space separated integers $N$ and $M$, number of important events in football and cricket match respectively.
Second line contain $N$ space separated integers $F_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the football match.
Third line contain $M$ space separated integers $C_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the cricket match.
------ Output: ------
For each testcase, output in a single line answer to the problem.
------ Constraints ------
$1 ≤ N, M ≤ 2.5*10^{4}$
$1 ≤ F_{i}, C_{i} ≤ 10^{9}$
$F_{i} > F_{i - 1}$ $\forall i > 0$
$C_{i} > C_{i - 1}$ $\forall i > 0$
$F_{i}$ != $C_{j}$ $\forall i, j$
Sum of $N$ over all tests is atmost $2*10^{5}$
Sum of $M$ over all tests is atmost $2*10^{5}$
----- Sample Input 1 ------
3
2 2
1 3
2 4
3 1
100 200 300
1
1 2
1
100 200
----- Sample Output 1 ------
3
2
1
----- explanation 1 ------
Case 1: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are already watching the same channel we won't switch. At $T = 2$,
there is an important event in cricket match and we switch the channel for the first time. At $T = 3$, there is an important event in football match and we switch the channel for the second time. At $T = 4$, there is an important event in cricket match and we switch the channel for the third time. So in total we switch three times.
Case 2: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in cricket match and we switch the channel for the first time. At $T = 100$, there is an important event in football match and we switch the channel for the second time. At $T = 200$, there is an important event in football match and since we are on the same channel, we don't switch. At $T = 300$, there is an important event in football match and since we are on the same channel, we don't switch. So in total we switch two times.
Case 3: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are on the same channel, we don't switch. At $T = 100$, there is an important event in cricket match and we switch the channel for the first time. At $T = 200$, there is an important event in cricket match and since we are on the same channel, we don't switch. So in total we switch only one time.
|
for _ in range(int(input())):
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = "f"
d = 0
x = y = 0
while True:
if c == "f":
if b[y] < a[x]:
d += 1
c = "c"
else:
x += 1
elif a[x] < b[y]:
d += 1
c = "f"
else:
y += 1
if x == n or y == m:
print(d + 1)
break
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER WHILE NUMBER IF VAR STRING IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR STRING VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR STRING VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
There is only $1$ TV in the common room, and as luck would have it, both the El Clasico football match and the India-Pakistan cricket match are happening simultaneously.
There is one football fan who is looking at the live commentary online and will scream whenever an 'important' event takes place in the El Clasico. Similarly, there is a cricket fan who will do so for every important event in the cricket match.
You are given two arrays - $F_{1}, F_{2}, \ldots, F_{n}$, which denote the times when an important event happens in the football match. And similarly $C_{1}, C_{2}, \ldots, C_{m}$ for cricket.
You sadly have the remote in hand. You start out by watching the El Clasico. But whenever an Important event happens in the sport which isn't on the TV right now, you will be forced to switch to that sport's channel, and this continues, i.e., you switch channels if and only if when an important event in the other sport happens.
Find the total number of times you will have to switch between the channels.
------ Input: ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of $3$ lines of input.
First line contain $2$ space separated integers $N$ and $M$, number of important events in football and cricket match respectively.
Second line contain $N$ space separated integers $F_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the football match.
Third line contain $M$ space separated integers $C_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the cricket match.
------ Output: ------
For each testcase, output in a single line answer to the problem.
------ Constraints ------
$1 ≤ N, M ≤ 2.5*10^{4}$
$1 ≤ F_{i}, C_{i} ≤ 10^{9}$
$F_{i} > F_{i - 1}$ $\forall i > 0$
$C_{i} > C_{i - 1}$ $\forall i > 0$
$F_{i}$ != $C_{j}$ $\forall i, j$
Sum of $N$ over all tests is atmost $2*10^{5}$
Sum of $M$ over all tests is atmost $2*10^{5}$
----- Sample Input 1 ------
3
2 2
1 3
2 4
3 1
100 200 300
1
1 2
1
100 200
----- Sample Output 1 ------
3
2
1
----- explanation 1 ------
Case 1: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are already watching the same channel we won't switch. At $T = 2$,
there is an important event in cricket match and we switch the channel for the first time. At $T = 3$, there is an important event in football match and we switch the channel for the second time. At $T = 4$, there is an important event in cricket match and we switch the channel for the third time. So in total we switch three times.
Case 2: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in cricket match and we switch the channel for the first time. At $T = 100$, there is an important event in football match and we switch the channel for the second time. At $T = 200$, there is an important event in football match and since we are on the same channel, we don't switch. At $T = 300$, there is an important event in football match and since we are on the same channel, we don't switch. So in total we switch two times.
Case 3: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are on the same channel, we don't switch. At $T = 100$, there is an important event in cricket match and we switch the channel for the first time. At $T = 200$, there is an important event in cricket match and since we are on the same channel, we don't switch. So in total we switch only one time.
|
t = int(input())
for i in range(t):
n, m = map(int, input().split())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
if 0 in l1 or 0 in l2:
continue
c = 0
flag = 0
sm = l1[0]
ptr1 = 0
ptr2 = 0
while ptr1 < n and ptr2 < m:
if l1[ptr1] < l2[ptr2]:
if flag == 1:
c = c + 1
flag = 0
ptr1 = ptr1 + 1
else:
if flag == 0:
c = c + 1
flag = 1
ptr2 = ptr2 + 1
if ptr1 < n and flag == 1:
c = c + 1
elif ptr2 < m and flag == 0:
c = c + 1
print(c)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF NUMBER VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There is only $1$ TV in the common room, and as luck would have it, both the El Clasico football match and the India-Pakistan cricket match are happening simultaneously.
There is one football fan who is looking at the live commentary online and will scream whenever an 'important' event takes place in the El Clasico. Similarly, there is a cricket fan who will do so for every important event in the cricket match.
You are given two arrays - $F_{1}, F_{2}, \ldots, F_{n}$, which denote the times when an important event happens in the football match. And similarly $C_{1}, C_{2}, \ldots, C_{m}$ for cricket.
You sadly have the remote in hand. You start out by watching the El Clasico. But whenever an Important event happens in the sport which isn't on the TV right now, you will be forced to switch to that sport's channel, and this continues, i.e., you switch channels if and only if when an important event in the other sport happens.
Find the total number of times you will have to switch between the channels.
------ Input: ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of $3$ lines of input.
First line contain $2$ space separated integers $N$ and $M$, number of important events in football and cricket match respectively.
Second line contain $N$ space separated integers $F_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the football match.
Third line contain $M$ space separated integers $C_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the cricket match.
------ Output: ------
For each testcase, output in a single line answer to the problem.
------ Constraints ------
$1 ≤ N, M ≤ 2.5*10^{4}$
$1 ≤ F_{i}, C_{i} ≤ 10^{9}$
$F_{i} > F_{i - 1}$ $\forall i > 0$
$C_{i} > C_{i - 1}$ $\forall i > 0$
$F_{i}$ != $C_{j}$ $\forall i, j$
Sum of $N$ over all tests is atmost $2*10^{5}$
Sum of $M$ over all tests is atmost $2*10^{5}$
----- Sample Input 1 ------
3
2 2
1 3
2 4
3 1
100 200 300
1
1 2
1
100 200
----- Sample Output 1 ------
3
2
1
----- explanation 1 ------
Case 1: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are already watching the same channel we won't switch. At $T = 2$,
there is an important event in cricket match and we switch the channel for the first time. At $T = 3$, there is an important event in football match and we switch the channel for the second time. At $T = 4$, there is an important event in cricket match and we switch the channel for the third time. So in total we switch three times.
Case 2: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in cricket match and we switch the channel for the first time. At $T = 100$, there is an important event in football match and we switch the channel for the second time. At $T = 200$, there is an important event in football match and since we are on the same channel, we don't switch. At $T = 300$, there is an important event in football match and since we are on the same channel, we don't switch. So in total we switch two times.
Case 3: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are on the same channel, we don't switch. At $T = 100$, there is an important event in cricket match and we switch the channel for the first time. At $T = 200$, there is an important event in cricket match and since we are on the same channel, we don't switch. So in total we switch only one time.
|
def ans():
ans = i = j = p = 0
while i < n and j < m:
if f[i] < c[j]:
if p != 0:
p = 0
ans += 1
i += 1
else:
if p == 0:
p = 1
ans += 1
j += 1
print(ans + 1)
for i in range(int(input())):
n, m = map(int, input().split())
f = list(map(int, input().split()))
c = list(map(int, input().split()))
ans()
|
FUNC_DEF ASSIGN VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR
|
There is only $1$ TV in the common room, and as luck would have it, both the El Clasico football match and the India-Pakistan cricket match are happening simultaneously.
There is one football fan who is looking at the live commentary online and will scream whenever an 'important' event takes place in the El Clasico. Similarly, there is a cricket fan who will do so for every important event in the cricket match.
You are given two arrays - $F_{1}, F_{2}, \ldots, F_{n}$, which denote the times when an important event happens in the football match. And similarly $C_{1}, C_{2}, \ldots, C_{m}$ for cricket.
You sadly have the remote in hand. You start out by watching the El Clasico. But whenever an Important event happens in the sport which isn't on the TV right now, you will be forced to switch to that sport's channel, and this continues, i.e., you switch channels if and only if when an important event in the other sport happens.
Find the total number of times you will have to switch between the channels.
------ Input: ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of $3$ lines of input.
First line contain $2$ space separated integers $N$ and $M$, number of important events in football and cricket match respectively.
Second line contain $N$ space separated integers $F_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the football match.
Third line contain $M$ space separated integers $C_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the cricket match.
------ Output: ------
For each testcase, output in a single line answer to the problem.
------ Constraints ------
$1 ≤ N, M ≤ 2.5*10^{4}$
$1 ≤ F_{i}, C_{i} ≤ 10^{9}$
$F_{i} > F_{i - 1}$ $\forall i > 0$
$C_{i} > C_{i - 1}$ $\forall i > 0$
$F_{i}$ != $C_{j}$ $\forall i, j$
Sum of $N$ over all tests is atmost $2*10^{5}$
Sum of $M$ over all tests is atmost $2*10^{5}$
----- Sample Input 1 ------
3
2 2
1 3
2 4
3 1
100 200 300
1
1 2
1
100 200
----- Sample Output 1 ------
3
2
1
----- explanation 1 ------
Case 1: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are already watching the same channel we won't switch. At $T = 2$,
there is an important event in cricket match and we switch the channel for the first time. At $T = 3$, there is an important event in football match and we switch the channel for the second time. At $T = 4$, there is an important event in cricket match and we switch the channel for the third time. So in total we switch three times.
Case 2: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in cricket match and we switch the channel for the first time. At $T = 100$, there is an important event in football match and we switch the channel for the second time. At $T = 200$, there is an important event in football match and since we are on the same channel, we don't switch. At $T = 300$, there is an important event in football match and since we are on the same channel, we don't switch. So in total we switch two times.
Case 3: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are on the same channel, we don't switch. At $T = 100$, there is an important event in cricket match and we switch the channel for the first time. At $T = 200$, there is an important event in cricket match and since we are on the same channel, we don't switch. So in total we switch only one time.
|
t = int(input())
for i in range(t):
N, M = map(int, input().split())
fb = list(map(int, input().split()))
ct = list(map(int, input().split()))
first = "fb"
count = 0
for i in range(N + M):
if fb != [] and ct != []:
if fb[0] < ct[0]:
present = "fb"
fb.pop(0)
else:
present = "ct"
ct.pop(0)
elif fb == []:
present = "ct"
elif ct == []:
present = "fb"
if first != present:
first = present
count += 1
print(count)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR LIST VAR LIST IF VAR NUMBER VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR LIST ASSIGN VAR STRING IF VAR LIST ASSIGN VAR STRING IF VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There is only $1$ TV in the common room, and as luck would have it, both the El Clasico football match and the India-Pakistan cricket match are happening simultaneously.
There is one football fan who is looking at the live commentary online and will scream whenever an 'important' event takes place in the El Clasico. Similarly, there is a cricket fan who will do so for every important event in the cricket match.
You are given two arrays - $F_{1}, F_{2}, \ldots, F_{n}$, which denote the times when an important event happens in the football match. And similarly $C_{1}, C_{2}, \ldots, C_{m}$ for cricket.
You sadly have the remote in hand. You start out by watching the El Clasico. But whenever an Important event happens in the sport which isn't on the TV right now, you will be forced to switch to that sport's channel, and this continues, i.e., you switch channels if and only if when an important event in the other sport happens.
Find the total number of times you will have to switch between the channels.
------ Input: ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of $3$ lines of input.
First line contain $2$ space separated integers $N$ and $M$, number of important events in football and cricket match respectively.
Second line contain $N$ space separated integers $F_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the football match.
Third line contain $M$ space separated integers $C_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the cricket match.
------ Output: ------
For each testcase, output in a single line answer to the problem.
------ Constraints ------
$1 ≤ N, M ≤ 2.5*10^{4}$
$1 ≤ F_{i}, C_{i} ≤ 10^{9}$
$F_{i} > F_{i - 1}$ $\forall i > 0$
$C_{i} > C_{i - 1}$ $\forall i > 0$
$F_{i}$ != $C_{j}$ $\forall i, j$
Sum of $N$ over all tests is atmost $2*10^{5}$
Sum of $M$ over all tests is atmost $2*10^{5}$
----- Sample Input 1 ------
3
2 2
1 3
2 4
3 1
100 200 300
1
1 2
1
100 200
----- Sample Output 1 ------
3
2
1
----- explanation 1 ------
Case 1: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are already watching the same channel we won't switch. At $T = 2$,
there is an important event in cricket match and we switch the channel for the first time. At $T = 3$, there is an important event in football match and we switch the channel for the second time. At $T = 4$, there is an important event in cricket match and we switch the channel for the third time. So in total we switch three times.
Case 2: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in cricket match and we switch the channel for the first time. At $T = 100$, there is an important event in football match and we switch the channel for the second time. At $T = 200$, there is an important event in football match and since we are on the same channel, we don't switch. At $T = 300$, there is an important event in football match and since we are on the same channel, we don't switch. So in total we switch two times.
Case 3: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are on the same channel, we don't switch. At $T = 100$, there is an important event in cricket match and we switch the channel for the first time. At $T = 200$, there is an important event in cricket match and since we are on the same channel, we don't switch. So in total we switch only one time.
|
from sys import stdin, stdout
try:
from sys import stdin, stdout
rl = lambda: stdin.readline()
wl = lambda s: stdout.write(s)
tc = int(rl())
for _ in range(tc):
n, m = map(int, rl().split())
F = list(map(int, rl().split()))
C = list(map(int, rl().split()))
r = f = c = p = 0
while f < n and c < m:
if F[f] < C[c]:
if p == 1:
p = 0
r += 1
f += 1
else:
if p == 0:
p = 1
r += 1
c += 1
wl(str(r + 1) + "\n")
except:
pass
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER STRING
|
There is only $1$ TV in the common room, and as luck would have it, both the El Clasico football match and the India-Pakistan cricket match are happening simultaneously.
There is one football fan who is looking at the live commentary online and will scream whenever an 'important' event takes place in the El Clasico. Similarly, there is a cricket fan who will do so for every important event in the cricket match.
You are given two arrays - $F_{1}, F_{2}, \ldots, F_{n}$, which denote the times when an important event happens in the football match. And similarly $C_{1}, C_{2}, \ldots, C_{m}$ for cricket.
You sadly have the remote in hand. You start out by watching the El Clasico. But whenever an Important event happens in the sport which isn't on the TV right now, you will be forced to switch to that sport's channel, and this continues, i.e., you switch channels if and only if when an important event in the other sport happens.
Find the total number of times you will have to switch between the channels.
------ Input: ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of $3$ lines of input.
First line contain $2$ space separated integers $N$ and $M$, number of important events in football and cricket match respectively.
Second line contain $N$ space separated integers $F_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the football match.
Third line contain $M$ space separated integers $C_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the cricket match.
------ Output: ------
For each testcase, output in a single line answer to the problem.
------ Constraints ------
$1 ≤ N, M ≤ 2.5*10^{4}$
$1 ≤ F_{i}, C_{i} ≤ 10^{9}$
$F_{i} > F_{i - 1}$ $\forall i > 0$
$C_{i} > C_{i - 1}$ $\forall i > 0$
$F_{i}$ != $C_{j}$ $\forall i, j$
Sum of $N$ over all tests is atmost $2*10^{5}$
Sum of $M$ over all tests is atmost $2*10^{5}$
----- Sample Input 1 ------
3
2 2
1 3
2 4
3 1
100 200 300
1
1 2
1
100 200
----- Sample Output 1 ------
3
2
1
----- explanation 1 ------
Case 1: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are already watching the same channel we won't switch. At $T = 2$,
there is an important event in cricket match and we switch the channel for the first time. At $T = 3$, there is an important event in football match and we switch the channel for the second time. At $T = 4$, there is an important event in cricket match and we switch the channel for the third time. So in total we switch three times.
Case 2: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in cricket match and we switch the channel for the first time. At $T = 100$, there is an important event in football match and we switch the channel for the second time. At $T = 200$, there is an important event in football match and since we are on the same channel, we don't switch. At $T = 300$, there is an important event in football match and since we are on the same channel, we don't switch. So in total we switch two times.
Case 3: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are on the same channel, we don't switch. At $T = 100$, there is an important event in cricket match and we switch the channel for the first time. At $T = 200$, there is an important event in cricket match and since we are on the same channel, we don't switch. So in total we switch only one time.
|
t = int(input())
for i in range(t):
n, m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
i = 0
j = 0
p = 1
c = 0
while i < n and j < m:
if a[i] < b[j]:
if p == 1:
i += 1
continue
else:
c += 1
p = 1
i += 1
elif p == 2:
j += 1
continue
else:
c += 1
p = 2
j += 1
print(c + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
There is only $1$ TV in the common room, and as luck would have it, both the El Clasico football match and the India-Pakistan cricket match are happening simultaneously.
There is one football fan who is looking at the live commentary online and will scream whenever an 'important' event takes place in the El Clasico. Similarly, there is a cricket fan who will do so for every important event in the cricket match.
You are given two arrays - $F_{1}, F_{2}, \ldots, F_{n}$, which denote the times when an important event happens in the football match. And similarly $C_{1}, C_{2}, \ldots, C_{m}$ for cricket.
You sadly have the remote in hand. You start out by watching the El Clasico. But whenever an Important event happens in the sport which isn't on the TV right now, you will be forced to switch to that sport's channel, and this continues, i.e., you switch channels if and only if when an important event in the other sport happens.
Find the total number of times you will have to switch between the channels.
------ Input: ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of $3$ lines of input.
First line contain $2$ space separated integers $N$ and $M$, number of important events in football and cricket match respectively.
Second line contain $N$ space separated integers $F_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the football match.
Third line contain $M$ space separated integers $C_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the cricket match.
------ Output: ------
For each testcase, output in a single line answer to the problem.
------ Constraints ------
$1 ≤ N, M ≤ 2.5*10^{4}$
$1 ≤ F_{i}, C_{i} ≤ 10^{9}$
$F_{i} > F_{i - 1}$ $\forall i > 0$
$C_{i} > C_{i - 1}$ $\forall i > 0$
$F_{i}$ != $C_{j}$ $\forall i, j$
Sum of $N$ over all tests is atmost $2*10^{5}$
Sum of $M$ over all tests is atmost $2*10^{5}$
----- Sample Input 1 ------
3
2 2
1 3
2 4
3 1
100 200 300
1
1 2
1
100 200
----- Sample Output 1 ------
3
2
1
----- explanation 1 ------
Case 1: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are already watching the same channel we won't switch. At $T = 2$,
there is an important event in cricket match and we switch the channel for the first time. At $T = 3$, there is an important event in football match and we switch the channel for the second time. At $T = 4$, there is an important event in cricket match and we switch the channel for the third time. So in total we switch three times.
Case 2: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in cricket match and we switch the channel for the first time. At $T = 100$, there is an important event in football match and we switch the channel for the second time. At $T = 200$, there is an important event in football match and since we are on the same channel, we don't switch. At $T = 300$, there is an important event in football match and since we are on the same channel, we don't switch. So in total we switch two times.
Case 3: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are on the same channel, we don't switch. At $T = 100$, there is an important event in cricket match and we switch the channel for the first time. At $T = 200$, there is an important event in cricket match and since we are on the same channel, we don't switch. So in total we switch only one time.
|
def integer_list():
return list(map(int, input().split()))
def main():
f.sort(reverse=True)
c.sort(reverse=True)
swich = 0
s = True
while f and c:
if f[-1] < c[-1] and s:
f.pop()
elif f[-1] <= c[-1] and not s:
f.pop()
s = not s
swich += 1
elif c[-1] < f[-1] and not s:
c.pop()
elif c[-1] <= f[-1] and s:
c.pop()
s = not s
swich += 1
if f and not s:
swich += 1
if c and s:
swich += 1
print(swich)
t = int(input())
for _ in range(t):
fn, cm = integer_list()
f = integer_list()
c = integer_list()
main()
|
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
There is only $1$ TV in the common room, and as luck would have it, both the El Clasico football match and the India-Pakistan cricket match are happening simultaneously.
There is one football fan who is looking at the live commentary online and will scream whenever an 'important' event takes place in the El Clasico. Similarly, there is a cricket fan who will do so for every important event in the cricket match.
You are given two arrays - $F_{1}, F_{2}, \ldots, F_{n}$, which denote the times when an important event happens in the football match. And similarly $C_{1}, C_{2}, \ldots, C_{m}$ for cricket.
You sadly have the remote in hand. You start out by watching the El Clasico. But whenever an Important event happens in the sport which isn't on the TV right now, you will be forced to switch to that sport's channel, and this continues, i.e., you switch channels if and only if when an important event in the other sport happens.
Find the total number of times you will have to switch between the channels.
------ Input: ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of $3$ lines of input.
First line contain $2$ space separated integers $N$ and $M$, number of important events in football and cricket match respectively.
Second line contain $N$ space separated integers $F_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the football match.
Third line contain $M$ space separated integers $C_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the cricket match.
------ Output: ------
For each testcase, output in a single line answer to the problem.
------ Constraints ------
$1 ≤ N, M ≤ 2.5*10^{4}$
$1 ≤ F_{i}, C_{i} ≤ 10^{9}$
$F_{i} > F_{i - 1}$ $\forall i > 0$
$C_{i} > C_{i - 1}$ $\forall i > 0$
$F_{i}$ != $C_{j}$ $\forall i, j$
Sum of $N$ over all tests is atmost $2*10^{5}$
Sum of $M$ over all tests is atmost $2*10^{5}$
----- Sample Input 1 ------
3
2 2
1 3
2 4
3 1
100 200 300
1
1 2
1
100 200
----- Sample Output 1 ------
3
2
1
----- explanation 1 ------
Case 1: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are already watching the same channel we won't switch. At $T = 2$,
there is an important event in cricket match and we switch the channel for the first time. At $T = 3$, there is an important event in football match and we switch the channel for the second time. At $T = 4$, there is an important event in cricket match and we switch the channel for the third time. So in total we switch three times.
Case 2: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in cricket match and we switch the channel for the first time. At $T = 100$, there is an important event in football match and we switch the channel for the second time. At $T = 200$, there is an important event in football match and since we are on the same channel, we don't switch. At $T = 300$, there is an important event in football match and since we are on the same channel, we don't switch. So in total we switch two times.
Case 3: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are on the same channel, we don't switch. At $T = 100$, there is an important event in cricket match and we switch the channel for the first time. At $T = 200$, there is an important event in cricket match and since we are on the same channel, we don't switch. So in total we switch only one time.
|
t = int(input())
for i in range(t):
n, m = map(int, input().split())
f = list(map(int, input().split()))
c = list(map(int, input().split()))
d = f + c
d.sort()
x = 0
z = {}
for i in range(n):
z[f[i]] = 1
for i in range(m):
z[c[i]] = 0
for i in range(len(d)):
if z[d[i]] == 0 and x % 2 == 0:
x += 1
if z[d[i]] == 1 and x % 2 == 1:
x += 1
print(x)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There is only $1$ TV in the common room, and as luck would have it, both the El Clasico football match and the India-Pakistan cricket match are happening simultaneously.
There is one football fan who is looking at the live commentary online and will scream whenever an 'important' event takes place in the El Clasico. Similarly, there is a cricket fan who will do so for every important event in the cricket match.
You are given two arrays - $F_{1}, F_{2}, \ldots, F_{n}$, which denote the times when an important event happens in the football match. And similarly $C_{1}, C_{2}, \ldots, C_{m}$ for cricket.
You sadly have the remote in hand. You start out by watching the El Clasico. But whenever an Important event happens in the sport which isn't on the TV right now, you will be forced to switch to that sport's channel, and this continues, i.e., you switch channels if and only if when an important event in the other sport happens.
Find the total number of times you will have to switch between the channels.
------ Input: ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of $3$ lines of input.
First line contain $2$ space separated integers $N$ and $M$, number of important events in football and cricket match respectively.
Second line contain $N$ space separated integers $F_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the football match.
Third line contain $M$ space separated integers $C_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the cricket match.
------ Output: ------
For each testcase, output in a single line answer to the problem.
------ Constraints ------
$1 ≤ N, M ≤ 2.5*10^{4}$
$1 ≤ F_{i}, C_{i} ≤ 10^{9}$
$F_{i} > F_{i - 1}$ $\forall i > 0$
$C_{i} > C_{i - 1}$ $\forall i > 0$
$F_{i}$ != $C_{j}$ $\forall i, j$
Sum of $N$ over all tests is atmost $2*10^{5}$
Sum of $M$ over all tests is atmost $2*10^{5}$
----- Sample Input 1 ------
3
2 2
1 3
2 4
3 1
100 200 300
1
1 2
1
100 200
----- Sample Output 1 ------
3
2
1
----- explanation 1 ------
Case 1: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are already watching the same channel we won't switch. At $T = 2$,
there is an important event in cricket match and we switch the channel for the first time. At $T = 3$, there is an important event in football match and we switch the channel for the second time. At $T = 4$, there is an important event in cricket match and we switch the channel for the third time. So in total we switch three times.
Case 2: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in cricket match and we switch the channel for the first time. At $T = 100$, there is an important event in football match and we switch the channel for the second time. At $T = 200$, there is an important event in football match and since we are on the same channel, we don't switch. At $T = 300$, there is an important event in football match and since we are on the same channel, we don't switch. So in total we switch two times.
Case 3: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are on the same channel, we don't switch. At $T = 100$, there is an important event in cricket match and we switch the channel for the first time. At $T = 200$, there is an important event in cricket match and since we are on the same channel, we don't switch. So in total we switch only one time.
|
import sys
t = int(input())
for i in range(t):
n, m = map(int, input().split())
f = [int(x) for x in sys.stdin.readline().split()]
c = [int(x) for x in sys.stdin.readline().split()]
o = 0
s = "f"
while len(c) != 0 and len(f) != 0:
if c[0] < f[0]:
c.pop(0)
if s == "f":
o += 1
s = "c"
else:
f.pop(0)
if s == "c":
o += 1
s = "f"
print(o + 1)
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING WHILE FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR STRING VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR STRING VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
There is only $1$ TV in the common room, and as luck would have it, both the El Clasico football match and the India-Pakistan cricket match are happening simultaneously.
There is one football fan who is looking at the live commentary online and will scream whenever an 'important' event takes place in the El Clasico. Similarly, there is a cricket fan who will do so for every important event in the cricket match.
You are given two arrays - $F_{1}, F_{2}, \ldots, F_{n}$, which denote the times when an important event happens in the football match. And similarly $C_{1}, C_{2}, \ldots, C_{m}$ for cricket.
You sadly have the remote in hand. You start out by watching the El Clasico. But whenever an Important event happens in the sport which isn't on the TV right now, you will be forced to switch to that sport's channel, and this continues, i.e., you switch channels if and only if when an important event in the other sport happens.
Find the total number of times you will have to switch between the channels.
------ Input: ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of $3$ lines of input.
First line contain $2$ space separated integers $N$ and $M$, number of important events in football and cricket match respectively.
Second line contain $N$ space separated integers $F_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the football match.
Third line contain $M$ space separated integers $C_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the cricket match.
------ Output: ------
For each testcase, output in a single line answer to the problem.
------ Constraints ------
$1 ≤ N, M ≤ 2.5*10^{4}$
$1 ≤ F_{i}, C_{i} ≤ 10^{9}$
$F_{i} > F_{i - 1}$ $\forall i > 0$
$C_{i} > C_{i - 1}$ $\forall i > 0$
$F_{i}$ != $C_{j}$ $\forall i, j$
Sum of $N$ over all tests is atmost $2*10^{5}$
Sum of $M$ over all tests is atmost $2*10^{5}$
----- Sample Input 1 ------
3
2 2
1 3
2 4
3 1
100 200 300
1
1 2
1
100 200
----- Sample Output 1 ------
3
2
1
----- explanation 1 ------
Case 1: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are already watching the same channel we won't switch. At $T = 2$,
there is an important event in cricket match and we switch the channel for the first time. At $T = 3$, there is an important event in football match and we switch the channel for the second time. At $T = 4$, there is an important event in cricket match and we switch the channel for the third time. So in total we switch three times.
Case 2: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in cricket match and we switch the channel for the first time. At $T = 100$, there is an important event in football match and we switch the channel for the second time. At $T = 200$, there is an important event in football match and since we are on the same channel, we don't switch. At $T = 300$, there is an important event in football match and since we are on the same channel, we don't switch. So in total we switch two times.
Case 3: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are on the same channel, we don't switch. At $T = 100$, there is an important event in cricket match and we switch the channel for the first time. At $T = 200$, there is an important event in cricket match and since we are on the same channel, we don't switch. So in total we switch only one time.
|
t = int(input())
for _ in range(t):
n, m = [int(x) for x in input().split()]
Lf = [int(x) for x in input().split()]
Lc = [int(x) for x in input().split()]
k = 0
f = 0
c = 0
current = "F"
while f < n and c < m:
if Lf[f] < Lc[c]:
if current != "F":
k += 1
current = "F"
f += 1
elif Lc[c] < Lf[f]:
if current != "C":
k += 1
current = "C"
c += 1
if f != n and current == "C":
k += 1
if c != m and current == "F":
k += 1
print(k)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR IF VAR STRING VAR NUMBER ASSIGN VAR STRING VAR NUMBER IF VAR VAR VAR VAR IF VAR STRING VAR NUMBER ASSIGN VAR STRING VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There is only $1$ TV in the common room, and as luck would have it, both the El Clasico football match and the India-Pakistan cricket match are happening simultaneously.
There is one football fan who is looking at the live commentary online and will scream whenever an 'important' event takes place in the El Clasico. Similarly, there is a cricket fan who will do so for every important event in the cricket match.
You are given two arrays - $F_{1}, F_{2}, \ldots, F_{n}$, which denote the times when an important event happens in the football match. And similarly $C_{1}, C_{2}, \ldots, C_{m}$ for cricket.
You sadly have the remote in hand. You start out by watching the El Clasico. But whenever an Important event happens in the sport which isn't on the TV right now, you will be forced to switch to that sport's channel, and this continues, i.e., you switch channels if and only if when an important event in the other sport happens.
Find the total number of times you will have to switch between the channels.
------ Input: ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of $3$ lines of input.
First line contain $2$ space separated integers $N$ and $M$, number of important events in football and cricket match respectively.
Second line contain $N$ space separated integers $F_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the football match.
Third line contain $M$ space separated integers $C_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the cricket match.
------ Output: ------
For each testcase, output in a single line answer to the problem.
------ Constraints ------
$1 ≤ N, M ≤ 2.5*10^{4}$
$1 ≤ F_{i}, C_{i} ≤ 10^{9}$
$F_{i} > F_{i - 1}$ $\forall i > 0$
$C_{i} > C_{i - 1}$ $\forall i > 0$
$F_{i}$ != $C_{j}$ $\forall i, j$
Sum of $N$ over all tests is atmost $2*10^{5}$
Sum of $M$ over all tests is atmost $2*10^{5}$
----- Sample Input 1 ------
3
2 2
1 3
2 4
3 1
100 200 300
1
1 2
1
100 200
----- Sample Output 1 ------
3
2
1
----- explanation 1 ------
Case 1: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are already watching the same channel we won't switch. At $T = 2$,
there is an important event in cricket match and we switch the channel for the first time. At $T = 3$, there is an important event in football match and we switch the channel for the second time. At $T = 4$, there is an important event in cricket match and we switch the channel for the third time. So in total we switch three times.
Case 2: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in cricket match and we switch the channel for the first time. At $T = 100$, there is an important event in football match and we switch the channel for the second time. At $T = 200$, there is an important event in football match and since we are on the same channel, we don't switch. At $T = 300$, there is an important event in football match and since we are on the same channel, we don't switch. So in total we switch two times.
Case 3: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are on the same channel, we don't switch. At $T = 100$, there is an important event in cricket match and we switch the channel for the first time. At $T = 200$, there is an important event in cricket match and since we are on the same channel, we don't switch. So in total we switch only one time.
|
tot = int(input())
for _ in range(tot):
nf, nc = map(int, input().split())
foot = set(map(int, input().split()))
crick = set(map(int, input().split()))
ev = list(foot.union(crick))
ev.sort()
chan = "foot"
s = 0
for i in ev:
if i in crick and chan != "crick":
s += 1
chan = "crick"
elif i in foot and chan != "foot":
s += 1
chan = "foot"
print(s)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR STRING IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
|
There is only $1$ TV in the common room, and as luck would have it, both the El Clasico football match and the India-Pakistan cricket match are happening simultaneously.
There is one football fan who is looking at the live commentary online and will scream whenever an 'important' event takes place in the El Clasico. Similarly, there is a cricket fan who will do so for every important event in the cricket match.
You are given two arrays - $F_{1}, F_{2}, \ldots, F_{n}$, which denote the times when an important event happens in the football match. And similarly $C_{1}, C_{2}, \ldots, C_{m}$ for cricket.
You sadly have the remote in hand. You start out by watching the El Clasico. But whenever an Important event happens in the sport which isn't on the TV right now, you will be forced to switch to that sport's channel, and this continues, i.e., you switch channels if and only if when an important event in the other sport happens.
Find the total number of times you will have to switch between the channels.
------ Input: ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of $3$ lines of input.
First line contain $2$ space separated integers $N$ and $M$, number of important events in football and cricket match respectively.
Second line contain $N$ space separated integers $F_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the football match.
Third line contain $M$ space separated integers $C_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the cricket match.
------ Output: ------
For each testcase, output in a single line answer to the problem.
------ Constraints ------
$1 ≤ N, M ≤ 2.5*10^{4}$
$1 ≤ F_{i}, C_{i} ≤ 10^{9}$
$F_{i} > F_{i - 1}$ $\forall i > 0$
$C_{i} > C_{i - 1}$ $\forall i > 0$
$F_{i}$ != $C_{j}$ $\forall i, j$
Sum of $N$ over all tests is atmost $2*10^{5}$
Sum of $M$ over all tests is atmost $2*10^{5}$
----- Sample Input 1 ------
3
2 2
1 3
2 4
3 1
100 200 300
1
1 2
1
100 200
----- Sample Output 1 ------
3
2
1
----- explanation 1 ------
Case 1: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are already watching the same channel we won't switch. At $T = 2$,
there is an important event in cricket match and we switch the channel for the first time. At $T = 3$, there is an important event in football match and we switch the channel for the second time. At $T = 4$, there is an important event in cricket match and we switch the channel for the third time. So in total we switch three times.
Case 2: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in cricket match and we switch the channel for the first time. At $T = 100$, there is an important event in football match and we switch the channel for the second time. At $T = 200$, there is an important event in football match and since we are on the same channel, we don't switch. At $T = 300$, there is an important event in football match and since we are on the same channel, we don't switch. So in total we switch two times.
Case 3: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are on the same channel, we don't switch. At $T = 100$, there is an important event in cricket match and we switch the channel for the first time. At $T = 200$, there is an important event in cricket match and since we are on the same channel, we don't switch. So in total we switch only one time.
|
a = int(input())
while a != 0:
ans = 0
now = 1
n, m = map(int, input().split())
f1 = list(map(int, input().split()))
f2 = list(map(int, input().split()))
timeline = [(i, 1) for i in f1] + [(i, 2) for i in f2]
timeline = sorted(timeline)
for i in timeline:
if i[1] != now:
ans = ans + 1
now = i[1]
print(ans)
a = a - 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER
|
There is only $1$ TV in the common room, and as luck would have it, both the El Clasico football match and the India-Pakistan cricket match are happening simultaneously.
There is one football fan who is looking at the live commentary online and will scream whenever an 'important' event takes place in the El Clasico. Similarly, there is a cricket fan who will do so for every important event in the cricket match.
You are given two arrays - $F_{1}, F_{2}, \ldots, F_{n}$, which denote the times when an important event happens in the football match. And similarly $C_{1}, C_{2}, \ldots, C_{m}$ for cricket.
You sadly have the remote in hand. You start out by watching the El Clasico. But whenever an Important event happens in the sport which isn't on the TV right now, you will be forced to switch to that sport's channel, and this continues, i.e., you switch channels if and only if when an important event in the other sport happens.
Find the total number of times you will have to switch between the channels.
------ Input: ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of $3$ lines of input.
First line contain $2$ space separated integers $N$ and $M$, number of important events in football and cricket match respectively.
Second line contain $N$ space separated integers $F_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the football match.
Third line contain $M$ space separated integers $C_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the cricket match.
------ Output: ------
For each testcase, output in a single line answer to the problem.
------ Constraints ------
$1 ≤ N, M ≤ 2.5*10^{4}$
$1 ≤ F_{i}, C_{i} ≤ 10^{9}$
$F_{i} > F_{i - 1}$ $\forall i > 0$
$C_{i} > C_{i - 1}$ $\forall i > 0$
$F_{i}$ != $C_{j}$ $\forall i, j$
Sum of $N$ over all tests is atmost $2*10^{5}$
Sum of $M$ over all tests is atmost $2*10^{5}$
----- Sample Input 1 ------
3
2 2
1 3
2 4
3 1
100 200 300
1
1 2
1
100 200
----- Sample Output 1 ------
3
2
1
----- explanation 1 ------
Case 1: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are already watching the same channel we won't switch. At $T = 2$,
there is an important event in cricket match and we switch the channel for the first time. At $T = 3$, there is an important event in football match and we switch the channel for the second time. At $T = 4$, there is an important event in cricket match and we switch the channel for the third time. So in total we switch three times.
Case 2: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in cricket match and we switch the channel for the first time. At $T = 100$, there is an important event in football match and we switch the channel for the second time. At $T = 200$, there is an important event in football match and since we are on the same channel, we don't switch. At $T = 300$, there is an important event in football match and since we are on the same channel, we don't switch. So in total we switch two times.
Case 3: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are on the same channel, we don't switch. At $T = 100$, there is an important event in cricket match and we switch the channel for the first time. At $T = 200$, there is an important event in cricket match and since we are on the same channel, we don't switch. So in total we switch only one time.
|
for _ in range(int(input())):
noOfFoot, noOfCric = map(int, input().split(" "))
footImpEvents = list(map(int, input().split(" ")))
cricImpEvents = list(map(int, input().split(" ")))
r = f = c = p = 0
while f < noOfFoot and c < noOfCric:
if footImpEvents[f] < cricImpEvents[c]:
if p == 1:
p = 0
r += 1
f += 1
else:
if p == 0:
p = 1
r += 1
c += 1
print(str(r + 1))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER
|
There is only $1$ TV in the common room, and as luck would have it, both the El Clasico football match and the India-Pakistan cricket match are happening simultaneously.
There is one football fan who is looking at the live commentary online and will scream whenever an 'important' event takes place in the El Clasico. Similarly, there is a cricket fan who will do so for every important event in the cricket match.
You are given two arrays - $F_{1}, F_{2}, \ldots, F_{n}$, which denote the times when an important event happens in the football match. And similarly $C_{1}, C_{2}, \ldots, C_{m}$ for cricket.
You sadly have the remote in hand. You start out by watching the El Clasico. But whenever an Important event happens in the sport which isn't on the TV right now, you will be forced to switch to that sport's channel, and this continues, i.e., you switch channels if and only if when an important event in the other sport happens.
Find the total number of times you will have to switch between the channels.
------ Input: ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of $3$ lines of input.
First line contain $2$ space separated integers $N$ and $M$, number of important events in football and cricket match respectively.
Second line contain $N$ space separated integers $F_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the football match.
Third line contain $M$ space separated integers $C_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the cricket match.
------ Output: ------
For each testcase, output in a single line answer to the problem.
------ Constraints ------
$1 ≤ N, M ≤ 2.5*10^{4}$
$1 ≤ F_{i}, C_{i} ≤ 10^{9}$
$F_{i} > F_{i - 1}$ $\forall i > 0$
$C_{i} > C_{i - 1}$ $\forall i > 0$
$F_{i}$ != $C_{j}$ $\forall i, j$
Sum of $N$ over all tests is atmost $2*10^{5}$
Sum of $M$ over all tests is atmost $2*10^{5}$
----- Sample Input 1 ------
3
2 2
1 3
2 4
3 1
100 200 300
1
1 2
1
100 200
----- Sample Output 1 ------
3
2
1
----- explanation 1 ------
Case 1: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are already watching the same channel we won't switch. At $T = 2$,
there is an important event in cricket match and we switch the channel for the first time. At $T = 3$, there is an important event in football match and we switch the channel for the second time. At $T = 4$, there is an important event in cricket match and we switch the channel for the third time. So in total we switch three times.
Case 2: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in cricket match and we switch the channel for the first time. At $T = 100$, there is an important event in football match and we switch the channel for the second time. At $T = 200$, there is an important event in football match and since we are on the same channel, we don't switch. At $T = 300$, there is an important event in football match and since we are on the same channel, we don't switch. So in total we switch two times.
Case 3: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are on the same channel, we don't switch. At $T = 100$, there is an important event in cricket match and we switch the channel for the first time. At $T = 200$, there is an important event in cricket match and since we are on the same channel, we don't switch. So in total we switch only one time.
|
t = int(input())
for z in range(t):
n, m = map(int, input().split())
f = list(map(int, input().split()))
c = list(map(int, input().split()))
i = 0
j = 0
k = 0
count = 0
while i < n and j < m:
if f[i] < c[j]:
if k == 1:
k = 0
count += 1
i += 1
elif c[j] < f[i]:
if k == 0:
k = 1
count += 1
j += 1
else:
i += 1
j += 1
if i < n:
if k == 1:
k = 0
count += 1
if j < m:
if k == 0:
k = 1
count += 1
print(count)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There is only $1$ TV in the common room, and as luck would have it, both the El Clasico football match and the India-Pakistan cricket match are happening simultaneously.
There is one football fan who is looking at the live commentary online and will scream whenever an 'important' event takes place in the El Clasico. Similarly, there is a cricket fan who will do so for every important event in the cricket match.
You are given two arrays - $F_{1}, F_{2}, \ldots, F_{n}$, which denote the times when an important event happens in the football match. And similarly $C_{1}, C_{2}, \ldots, C_{m}$ for cricket.
You sadly have the remote in hand. You start out by watching the El Clasico. But whenever an Important event happens in the sport which isn't on the TV right now, you will be forced to switch to that sport's channel, and this continues, i.e., you switch channels if and only if when an important event in the other sport happens.
Find the total number of times you will have to switch between the channels.
------ Input: ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of $3$ lines of input.
First line contain $2$ space separated integers $N$ and $M$, number of important events in football and cricket match respectively.
Second line contain $N$ space separated integers $F_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the football match.
Third line contain $M$ space separated integers $C_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the cricket match.
------ Output: ------
For each testcase, output in a single line answer to the problem.
------ Constraints ------
$1 ≤ N, M ≤ 2.5*10^{4}$
$1 ≤ F_{i}, C_{i} ≤ 10^{9}$
$F_{i} > F_{i - 1}$ $\forall i > 0$
$C_{i} > C_{i - 1}$ $\forall i > 0$
$F_{i}$ != $C_{j}$ $\forall i, j$
Sum of $N$ over all tests is atmost $2*10^{5}$
Sum of $M$ over all tests is atmost $2*10^{5}$
----- Sample Input 1 ------
3
2 2
1 3
2 4
3 1
100 200 300
1
1 2
1
100 200
----- Sample Output 1 ------
3
2
1
----- explanation 1 ------
Case 1: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are already watching the same channel we won't switch. At $T = 2$,
there is an important event in cricket match and we switch the channel for the first time. At $T = 3$, there is an important event in football match and we switch the channel for the second time. At $T = 4$, there is an important event in cricket match and we switch the channel for the third time. So in total we switch three times.
Case 2: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in cricket match and we switch the channel for the first time. At $T = 100$, there is an important event in football match and we switch the channel for the second time. At $T = 200$, there is an important event in football match and since we are on the same channel, we don't switch. At $T = 300$, there is an important event in football match and since we are on the same channel, we don't switch. So in total we switch two times.
Case 3: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are on the same channel, we don't switch. At $T = 100$, there is an important event in cricket match and we switch the channel for the first time. At $T = 200$, there is an important event in cricket match and since we are on the same channel, we don't switch. So in total we switch only one time.
|
try:
t = int(input())
for i in range(t):
n, m = [int(itm) for itm in input().split()]
ma = {}
f = [int(itm) for itm in input().split()]
c = [int(itm) for itm in input().split()]
for itm in f:
ma[itm] = "F"
for itm in c:
ma[itm] = "C"
mt = {(0): "F"}
for itm in sorted(ma.keys()):
mt[itm] = ma[itm]
check = "F"
count = 0
for itm in mt.keys():
if mt[itm] != check:
count += 1
check = mt[itm]
print(count)
except EOFError:
exit()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR STRING FOR VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR DICT NUMBER STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
|
There is only $1$ TV in the common room, and as luck would have it, both the El Clasico football match and the India-Pakistan cricket match are happening simultaneously.
There is one football fan who is looking at the live commentary online and will scream whenever an 'important' event takes place in the El Clasico. Similarly, there is a cricket fan who will do so for every important event in the cricket match.
You are given two arrays - $F_{1}, F_{2}, \ldots, F_{n}$, which denote the times when an important event happens in the football match. And similarly $C_{1}, C_{2}, \ldots, C_{m}$ for cricket.
You sadly have the remote in hand. You start out by watching the El Clasico. But whenever an Important event happens in the sport which isn't on the TV right now, you will be forced to switch to that sport's channel, and this continues, i.e., you switch channels if and only if when an important event in the other sport happens.
Find the total number of times you will have to switch between the channels.
------ Input: ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of $3$ lines of input.
First line contain $2$ space separated integers $N$ and $M$, number of important events in football and cricket match respectively.
Second line contain $N$ space separated integers $F_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the football match.
Third line contain $M$ space separated integers $C_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the cricket match.
------ Output: ------
For each testcase, output in a single line answer to the problem.
------ Constraints ------
$1 ≤ N, M ≤ 2.5*10^{4}$
$1 ≤ F_{i}, C_{i} ≤ 10^{9}$
$F_{i} > F_{i - 1}$ $\forall i > 0$
$C_{i} > C_{i - 1}$ $\forall i > 0$
$F_{i}$ != $C_{j}$ $\forall i, j$
Sum of $N$ over all tests is atmost $2*10^{5}$
Sum of $M$ over all tests is atmost $2*10^{5}$
----- Sample Input 1 ------
3
2 2
1 3
2 4
3 1
100 200 300
1
1 2
1
100 200
----- Sample Output 1 ------
3
2
1
----- explanation 1 ------
Case 1: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are already watching the same channel we won't switch. At $T = 2$,
there is an important event in cricket match and we switch the channel for the first time. At $T = 3$, there is an important event in football match and we switch the channel for the second time. At $T = 4$, there is an important event in cricket match and we switch the channel for the third time. So in total we switch three times.
Case 2: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in cricket match and we switch the channel for the first time. At $T = 100$, there is an important event in football match and we switch the channel for the second time. At $T = 200$, there is an important event in football match and since we are on the same channel, we don't switch. At $T = 300$, there is an important event in football match and since we are on the same channel, we don't switch. So in total we switch two times.
Case 3: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are on the same channel, we don't switch. At $T = 100$, there is an important event in cricket match and we switch the channel for the first time. At $T = 200$, there is an important event in cricket match and since we are on the same channel, we don't switch. So in total we switch only one time.
|
def solve(A, n, B, m):
C = [(i, 0) for i in A]
C += [(i, 1) for i in B]
C.sort()
change = 0
curr = 0
for tim, sport in C:
if curr != sport:
change += 1
curr = sport
return change
for case in range(int(input())):
n, m = map(int, input().split())
F = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = solve(F, n, C, m)
print(ans)
|
FUNC_DEF ASSIGN VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
There is only $1$ TV in the common room, and as luck would have it, both the El Clasico football match and the India-Pakistan cricket match are happening simultaneously.
There is one football fan who is looking at the live commentary online and will scream whenever an 'important' event takes place in the El Clasico. Similarly, there is a cricket fan who will do so for every important event in the cricket match.
You are given two arrays - $F_{1}, F_{2}, \ldots, F_{n}$, which denote the times when an important event happens in the football match. And similarly $C_{1}, C_{2}, \ldots, C_{m}$ for cricket.
You sadly have the remote in hand. You start out by watching the El Clasico. But whenever an Important event happens in the sport which isn't on the TV right now, you will be forced to switch to that sport's channel, and this continues, i.e., you switch channels if and only if when an important event in the other sport happens.
Find the total number of times you will have to switch between the channels.
------ Input: ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of $3$ lines of input.
First line contain $2$ space separated integers $N$ and $M$, number of important events in football and cricket match respectively.
Second line contain $N$ space separated integers $F_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the football match.
Third line contain $M$ space separated integers $C_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the cricket match.
------ Output: ------
For each testcase, output in a single line answer to the problem.
------ Constraints ------
$1 ≤ N, M ≤ 2.5*10^{4}$
$1 ≤ F_{i}, C_{i} ≤ 10^{9}$
$F_{i} > F_{i - 1}$ $\forall i > 0$
$C_{i} > C_{i - 1}$ $\forall i > 0$
$F_{i}$ != $C_{j}$ $\forall i, j$
Sum of $N$ over all tests is atmost $2*10^{5}$
Sum of $M$ over all tests is atmost $2*10^{5}$
----- Sample Input 1 ------
3
2 2
1 3
2 4
3 1
100 200 300
1
1 2
1
100 200
----- Sample Output 1 ------
3
2
1
----- explanation 1 ------
Case 1: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are already watching the same channel we won't switch. At $T = 2$,
there is an important event in cricket match and we switch the channel for the first time. At $T = 3$, there is an important event in football match and we switch the channel for the second time. At $T = 4$, there is an important event in cricket match and we switch the channel for the third time. So in total we switch three times.
Case 2: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in cricket match and we switch the channel for the first time. At $T = 100$, there is an important event in football match and we switch the channel for the second time. At $T = 200$, there is an important event in football match and since we are on the same channel, we don't switch. At $T = 300$, there is an important event in football match and since we are on the same channel, we don't switch. So in total we switch two times.
Case 3: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are on the same channel, we don't switch. At $T = 100$, there is an important event in cricket match and we switch the channel for the first time. At $T = 200$, there is an important event in cricket match and since we are on the same channel, we don't switch. So in total we switch only one time.
|
t = int(input())
while t != 0:
n, m = list(map(int, input().split()))
foot = list(map(int, input().split()))
cric = list(map(int, input().split()))
switches = 0
chanel = 0
event = []
for i in foot:
event.append([i, 0])
for j in cric:
event.append([j, 1])
event = sorted(event, key=lambda x: x[0])
i = 0
while i < len(event):
if event[i][1] != chanel:
switches += 1
chanel = 1 - chanel
i += 1
print(switches)
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR LIST VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR LIST VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER
|
There is only $1$ TV in the common room, and as luck would have it, both the El Clasico football match and the India-Pakistan cricket match are happening simultaneously.
There is one football fan who is looking at the live commentary online and will scream whenever an 'important' event takes place in the El Clasico. Similarly, there is a cricket fan who will do so for every important event in the cricket match.
You are given two arrays - $F_{1}, F_{2}, \ldots, F_{n}$, which denote the times when an important event happens in the football match. And similarly $C_{1}, C_{2}, \ldots, C_{m}$ for cricket.
You sadly have the remote in hand. You start out by watching the El Clasico. But whenever an Important event happens in the sport which isn't on the TV right now, you will be forced to switch to that sport's channel, and this continues, i.e., you switch channels if and only if when an important event in the other sport happens.
Find the total number of times you will have to switch between the channels.
------ Input: ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of $3$ lines of input.
First line contain $2$ space separated integers $N$ and $M$, number of important events in football and cricket match respectively.
Second line contain $N$ space separated integers $F_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the football match.
Third line contain $M$ space separated integers $C_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the cricket match.
------ Output: ------
For each testcase, output in a single line answer to the problem.
------ Constraints ------
$1 ≤ N, M ≤ 2.5*10^{4}$
$1 ≤ F_{i}, C_{i} ≤ 10^{9}$
$F_{i} > F_{i - 1}$ $\forall i > 0$
$C_{i} > C_{i - 1}$ $\forall i > 0$
$F_{i}$ != $C_{j}$ $\forall i, j$
Sum of $N$ over all tests is atmost $2*10^{5}$
Sum of $M$ over all tests is atmost $2*10^{5}$
----- Sample Input 1 ------
3
2 2
1 3
2 4
3 1
100 200 300
1
1 2
1
100 200
----- Sample Output 1 ------
3
2
1
----- explanation 1 ------
Case 1: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are already watching the same channel we won't switch. At $T = 2$,
there is an important event in cricket match and we switch the channel for the first time. At $T = 3$, there is an important event in football match and we switch the channel for the second time. At $T = 4$, there is an important event in cricket match and we switch the channel for the third time. So in total we switch three times.
Case 2: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in cricket match and we switch the channel for the first time. At $T = 100$, there is an important event in football match and we switch the channel for the second time. At $T = 200$, there is an important event in football match and since we are on the same channel, we don't switch. At $T = 300$, there is an important event in football match and since we are on the same channel, we don't switch. So in total we switch two times.
Case 3: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are on the same channel, we don't switch. At $T = 100$, there is an important event in cricket match and we switch the channel for the first time. At $T = 200$, there is an important event in cricket match and since we are on the same channel, we don't switch. So in total we switch only one time.
|
t = int(input())
for i in range(t):
n, m = map(int, input().split())
f = list(map(int, input().split()))
c = list(map(int, input().split()))
l = []
for i in range(n):
l.append((f[i], "f"))
for j in range(m):
l.append((c[j], "c"))
prev = "f"
l.sort()
c = 0
for i in range(n + m):
try:
if l[i][1] != prev:
c += 1
except IndexError:
pass
prev = l[i][1]
print(c)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There is only $1$ TV in the common room, and as luck would have it, both the El Clasico football match and the India-Pakistan cricket match are happening simultaneously.
There is one football fan who is looking at the live commentary online and will scream whenever an 'important' event takes place in the El Clasico. Similarly, there is a cricket fan who will do so for every important event in the cricket match.
You are given two arrays - $F_{1}, F_{2}, \ldots, F_{n}$, which denote the times when an important event happens in the football match. And similarly $C_{1}, C_{2}, \ldots, C_{m}$ for cricket.
You sadly have the remote in hand. You start out by watching the El Clasico. But whenever an Important event happens in the sport which isn't on the TV right now, you will be forced to switch to that sport's channel, and this continues, i.e., you switch channels if and only if when an important event in the other sport happens.
Find the total number of times you will have to switch between the channels.
------ Input: ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of $3$ lines of input.
First line contain $2$ space separated integers $N$ and $M$, number of important events in football and cricket match respectively.
Second line contain $N$ space separated integers $F_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the football match.
Third line contain $M$ space separated integers $C_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the cricket match.
------ Output: ------
For each testcase, output in a single line answer to the problem.
------ Constraints ------
$1 ≤ N, M ≤ 2.5*10^{4}$
$1 ≤ F_{i}, C_{i} ≤ 10^{9}$
$F_{i} > F_{i - 1}$ $\forall i > 0$
$C_{i} > C_{i - 1}$ $\forall i > 0$
$F_{i}$ != $C_{j}$ $\forall i, j$
Sum of $N$ over all tests is atmost $2*10^{5}$
Sum of $M$ over all tests is atmost $2*10^{5}$
----- Sample Input 1 ------
3
2 2
1 3
2 4
3 1
100 200 300
1
1 2
1
100 200
----- Sample Output 1 ------
3
2
1
----- explanation 1 ------
Case 1: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are already watching the same channel we won't switch. At $T = 2$,
there is an important event in cricket match and we switch the channel for the first time. At $T = 3$, there is an important event in football match and we switch the channel for the second time. At $T = 4$, there is an important event in cricket match and we switch the channel for the third time. So in total we switch three times.
Case 2: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in cricket match and we switch the channel for the first time. At $T = 100$, there is an important event in football match and we switch the channel for the second time. At $T = 200$, there is an important event in football match and since we are on the same channel, we don't switch. At $T = 300$, there is an important event in football match and since we are on the same channel, we don't switch. So in total we switch two times.
Case 3: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are on the same channel, we don't switch. At $T = 100$, there is an important event in cricket match and we switch the channel for the first time. At $T = 200$, there is an important event in cricket match and since we are on the same channel, we don't switch. So in total we switch only one time.
|
for _ in range(int(input())):
n, m = map(int, input().split())
f = list(map(int, input().split()))
c = list(map(int, input().split()))
a = [(it, 0) for it in f]
a += [(it, 1) for it in c]
a.sort()
curr = 0
turn = 0
for event, sport in a:
if sport != curr:
turn += 1
curr = sport
print(turn)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
There is only $1$ TV in the common room, and as luck would have it, both the El Clasico football match and the India-Pakistan cricket match are happening simultaneously.
There is one football fan who is looking at the live commentary online and will scream whenever an 'important' event takes place in the El Clasico. Similarly, there is a cricket fan who will do so for every important event in the cricket match.
You are given two arrays - $F_{1}, F_{2}, \ldots, F_{n}$, which denote the times when an important event happens in the football match. And similarly $C_{1}, C_{2}, \ldots, C_{m}$ for cricket.
You sadly have the remote in hand. You start out by watching the El Clasico. But whenever an Important event happens in the sport which isn't on the TV right now, you will be forced to switch to that sport's channel, and this continues, i.e., you switch channels if and only if when an important event in the other sport happens.
Find the total number of times you will have to switch between the channels.
------ Input: ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of $3$ lines of input.
First line contain $2$ space separated integers $N$ and $M$, number of important events in football and cricket match respectively.
Second line contain $N$ space separated integers $F_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the football match.
Third line contain $M$ space separated integers $C_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the cricket match.
------ Output: ------
For each testcase, output in a single line answer to the problem.
------ Constraints ------
$1 ≤ N, M ≤ 2.5*10^{4}$
$1 ≤ F_{i}, C_{i} ≤ 10^{9}$
$F_{i} > F_{i - 1}$ $\forall i > 0$
$C_{i} > C_{i - 1}$ $\forall i > 0$
$F_{i}$ != $C_{j}$ $\forall i, j$
Sum of $N$ over all tests is atmost $2*10^{5}$
Sum of $M$ over all tests is atmost $2*10^{5}$
----- Sample Input 1 ------
3
2 2
1 3
2 4
3 1
100 200 300
1
1 2
1
100 200
----- Sample Output 1 ------
3
2
1
----- explanation 1 ------
Case 1: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are already watching the same channel we won't switch. At $T = 2$,
there is an important event in cricket match and we switch the channel for the first time. At $T = 3$, there is an important event in football match and we switch the channel for the second time. At $T = 4$, there is an important event in cricket match and we switch the channel for the third time. So in total we switch three times.
Case 2: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in cricket match and we switch the channel for the first time. At $T = 100$, there is an important event in football match and we switch the channel for the second time. At $T = 200$, there is an important event in football match and since we are on the same channel, we don't switch. At $T = 300$, there is an important event in football match and since we are on the same channel, we don't switch. So in total we switch two times.
Case 3: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are on the same channel, we don't switch. At $T = 100$, there is an important event in cricket match and we switch the channel for the first time. At $T = 200$, there is an important event in cricket match and since we are on the same channel, we don't switch. So in total we switch only one time.
|
def hs(s, t):
g = 0
a = 0
i, j = 0, 0
while i < len(s) and j < len(t):
if s[i] < t[j]:
if g == 1:
a = a + 1
g = 0
i = i + 1
else:
if g == 0:
a = a + 1
g = 1
j = j + 1
if i == len(s):
a = a + 1
if j == len(t):
a = a + 1
return a
t = int(input())
for _ in range(t):
f, c = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))
print(hs(s, t))
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
There is only $1$ TV in the common room, and as luck would have it, both the El Clasico football match and the India-Pakistan cricket match are happening simultaneously.
There is one football fan who is looking at the live commentary online and will scream whenever an 'important' event takes place in the El Clasico. Similarly, there is a cricket fan who will do so for every important event in the cricket match.
You are given two arrays - $F_{1}, F_{2}, \ldots, F_{n}$, which denote the times when an important event happens in the football match. And similarly $C_{1}, C_{2}, \ldots, C_{m}$ for cricket.
You sadly have the remote in hand. You start out by watching the El Clasico. But whenever an Important event happens in the sport which isn't on the TV right now, you will be forced to switch to that sport's channel, and this continues, i.e., you switch channels if and only if when an important event in the other sport happens.
Find the total number of times you will have to switch between the channels.
------ Input: ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of $3$ lines of input.
First line contain $2$ space separated integers $N$ and $M$, number of important events in football and cricket match respectively.
Second line contain $N$ space separated integers $F_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the football match.
Third line contain $M$ space separated integers $C_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the cricket match.
------ Output: ------
For each testcase, output in a single line answer to the problem.
------ Constraints ------
$1 ≤ N, M ≤ 2.5*10^{4}$
$1 ≤ F_{i}, C_{i} ≤ 10^{9}$
$F_{i} > F_{i - 1}$ $\forall i > 0$
$C_{i} > C_{i - 1}$ $\forall i > 0$
$F_{i}$ != $C_{j}$ $\forall i, j$
Sum of $N$ over all tests is atmost $2*10^{5}$
Sum of $M$ over all tests is atmost $2*10^{5}$
----- Sample Input 1 ------
3
2 2
1 3
2 4
3 1
100 200 300
1
1 2
1
100 200
----- Sample Output 1 ------
3
2
1
----- explanation 1 ------
Case 1: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are already watching the same channel we won't switch. At $T = 2$,
there is an important event in cricket match and we switch the channel for the first time. At $T = 3$, there is an important event in football match and we switch the channel for the second time. At $T = 4$, there is an important event in cricket match and we switch the channel for the third time. So in total we switch three times.
Case 2: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in cricket match and we switch the channel for the first time. At $T = 100$, there is an important event in football match and we switch the channel for the second time. At $T = 200$, there is an important event in football match and since we are on the same channel, we don't switch. At $T = 300$, there is an important event in football match and since we are on the same channel, we don't switch. So in total we switch two times.
Case 3: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are on the same channel, we don't switch. At $T = 100$, there is an important event in cricket match and we switch the channel for the first time. At $T = 200$, there is an important event in cricket match and since we are on the same channel, we don't switch. So in total we switch only one time.
|
t = int(input())
for _ in range(t):
m, n = map(int, input().split())
foot = list(map(int, input().split()))
cric = list(map(int, input().split()))
chan = 1
ans = 0
te = [(i, 1) for i in foot] + [(j, 2) for j in cric]
te = sorted(te)
for i in te:
if i[1] != chan:
ans += 1
chan = i[1]
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There is only $1$ TV in the common room, and as luck would have it, both the El Clasico football match and the India-Pakistan cricket match are happening simultaneously.
There is one football fan who is looking at the live commentary online and will scream whenever an 'important' event takes place in the El Clasico. Similarly, there is a cricket fan who will do so for every important event in the cricket match.
You are given two arrays - $F_{1}, F_{2}, \ldots, F_{n}$, which denote the times when an important event happens in the football match. And similarly $C_{1}, C_{2}, \ldots, C_{m}$ for cricket.
You sadly have the remote in hand. You start out by watching the El Clasico. But whenever an Important event happens in the sport which isn't on the TV right now, you will be forced to switch to that sport's channel, and this continues, i.e., you switch channels if and only if when an important event in the other sport happens.
Find the total number of times you will have to switch between the channels.
------ Input: ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of $3$ lines of input.
First line contain $2$ space separated integers $N$ and $M$, number of important events in football and cricket match respectively.
Second line contain $N$ space separated integers $F_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the football match.
Third line contain $M$ space separated integers $C_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the cricket match.
------ Output: ------
For each testcase, output in a single line answer to the problem.
------ Constraints ------
$1 ≤ N, M ≤ 2.5*10^{4}$
$1 ≤ F_{i}, C_{i} ≤ 10^{9}$
$F_{i} > F_{i - 1}$ $\forall i > 0$
$C_{i} > C_{i - 1}$ $\forall i > 0$
$F_{i}$ != $C_{j}$ $\forall i, j$
Sum of $N$ over all tests is atmost $2*10^{5}$
Sum of $M$ over all tests is atmost $2*10^{5}$
----- Sample Input 1 ------
3
2 2
1 3
2 4
3 1
100 200 300
1
1 2
1
100 200
----- Sample Output 1 ------
3
2
1
----- explanation 1 ------
Case 1: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are already watching the same channel we won't switch. At $T = 2$,
there is an important event in cricket match and we switch the channel for the first time. At $T = 3$, there is an important event in football match and we switch the channel for the second time. At $T = 4$, there is an important event in cricket match and we switch the channel for the third time. So in total we switch three times.
Case 2: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in cricket match and we switch the channel for the first time. At $T = 100$, there is an important event in football match and we switch the channel for the second time. At $T = 200$, there is an important event in football match and since we are on the same channel, we don't switch. At $T = 300$, there is an important event in football match and since we are on the same channel, we don't switch. So in total we switch two times.
Case 3: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are on the same channel, we don't switch. At $T = 100$, there is an important event in cricket match and we switch the channel for the first time. At $T = 200$, there is an important event in cricket match and since we are on the same channel, we don't switch. So in total we switch only one time.
|
for cases in range(int(input())):
n, m = map(int, input().split())
arr = list(map(int, input().split()))
cric = list(map(int, input().split()))
d = {}
current_pos = "f"
change = 0
for i in range(n):
d[arr[i]] = "f"
for j in range(m):
d[cric[j]] = "c"
arr.append(cric[j])
arr.sort()
for ele in arr:
if d[ele] != current_pos:
change += 1
current_pos = d[ele]
print(change)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
There is only $1$ TV in the common room, and as luck would have it, both the El Clasico football match and the India-Pakistan cricket match are happening simultaneously.
There is one football fan who is looking at the live commentary online and will scream whenever an 'important' event takes place in the El Clasico. Similarly, there is a cricket fan who will do so for every important event in the cricket match.
You are given two arrays - $F_{1}, F_{2}, \ldots, F_{n}$, which denote the times when an important event happens in the football match. And similarly $C_{1}, C_{2}, \ldots, C_{m}$ for cricket.
You sadly have the remote in hand. You start out by watching the El Clasico. But whenever an Important event happens in the sport which isn't on the TV right now, you will be forced to switch to that sport's channel, and this continues, i.e., you switch channels if and only if when an important event in the other sport happens.
Find the total number of times you will have to switch between the channels.
------ Input: ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of $3$ lines of input.
First line contain $2$ space separated integers $N$ and $M$, number of important events in football and cricket match respectively.
Second line contain $N$ space separated integers $F_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the football match.
Third line contain $M$ space separated integers $C_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the cricket match.
------ Output: ------
For each testcase, output in a single line answer to the problem.
------ Constraints ------
$1 ≤ N, M ≤ 2.5*10^{4}$
$1 ≤ F_{i}, C_{i} ≤ 10^{9}$
$F_{i} > F_{i - 1}$ $\forall i > 0$
$C_{i} > C_{i - 1}$ $\forall i > 0$
$F_{i}$ != $C_{j}$ $\forall i, j$
Sum of $N$ over all tests is atmost $2*10^{5}$
Sum of $M$ over all tests is atmost $2*10^{5}$
----- Sample Input 1 ------
3
2 2
1 3
2 4
3 1
100 200 300
1
1 2
1
100 200
----- Sample Output 1 ------
3
2
1
----- explanation 1 ------
Case 1: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are already watching the same channel we won't switch. At $T = 2$,
there is an important event in cricket match and we switch the channel for the first time. At $T = 3$, there is an important event in football match and we switch the channel for the second time. At $T = 4$, there is an important event in cricket match and we switch the channel for the third time. So in total we switch three times.
Case 2: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in cricket match and we switch the channel for the first time. At $T = 100$, there is an important event in football match and we switch the channel for the second time. At $T = 200$, there is an important event in football match and since we are on the same channel, we don't switch. At $T = 300$, there is an important event in football match and since we are on the same channel, we don't switch. So in total we switch two times.
Case 3: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are on the same channel, we don't switch. At $T = 100$, there is an important event in cricket match and we switch the channel for the first time. At $T = 200$, there is an important event in cricket match and since we are on the same channel, we don't switch. So in total we switch only one time.
|
t = int(input())
for i in range(t):
n, m = map(int, input().split())
l = []
f = list(map(int, input().split()))
c = list(map(int, input().split()))
current = "f"
count = 0
for i in range(n):
l.append((f[i], "f"))
for i in range(m):
l.append((c[i], "c"))
l.sort()
for i in range(len(l)):
if l[i][1] != current and current == "f":
count = count + 1
current = "c"
continue
if l[i][1] != current and current == "c":
count = count + 1
current = "f"
print(count)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR STRING IF VAR VAR NUMBER VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
|
There is only $1$ TV in the common room, and as luck would have it, both the El Clasico football match and the India-Pakistan cricket match are happening simultaneously.
There is one football fan who is looking at the live commentary online and will scream whenever an 'important' event takes place in the El Clasico. Similarly, there is a cricket fan who will do so for every important event in the cricket match.
You are given two arrays - $F_{1}, F_{2}, \ldots, F_{n}$, which denote the times when an important event happens in the football match. And similarly $C_{1}, C_{2}, \ldots, C_{m}$ for cricket.
You sadly have the remote in hand. You start out by watching the El Clasico. But whenever an Important event happens in the sport which isn't on the TV right now, you will be forced to switch to that sport's channel, and this continues, i.e., you switch channels if and only if when an important event in the other sport happens.
Find the total number of times you will have to switch between the channels.
------ Input: ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of $3$ lines of input.
First line contain $2$ space separated integers $N$ and $M$, number of important events in football and cricket match respectively.
Second line contain $N$ space separated integers $F_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the football match.
Third line contain $M$ space separated integers $C_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the cricket match.
------ Output: ------
For each testcase, output in a single line answer to the problem.
------ Constraints ------
$1 ≤ N, M ≤ 2.5*10^{4}$
$1 ≤ F_{i}, C_{i} ≤ 10^{9}$
$F_{i} > F_{i - 1}$ $\forall i > 0$
$C_{i} > C_{i - 1}$ $\forall i > 0$
$F_{i}$ != $C_{j}$ $\forall i, j$
Sum of $N$ over all tests is atmost $2*10^{5}$
Sum of $M$ over all tests is atmost $2*10^{5}$
----- Sample Input 1 ------
3
2 2
1 3
2 4
3 1
100 200 300
1
1 2
1
100 200
----- Sample Output 1 ------
3
2
1
----- explanation 1 ------
Case 1: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are already watching the same channel we won't switch. At $T = 2$,
there is an important event in cricket match and we switch the channel for the first time. At $T = 3$, there is an important event in football match and we switch the channel for the second time. At $T = 4$, there is an important event in cricket match and we switch the channel for the third time. So in total we switch three times.
Case 2: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in cricket match and we switch the channel for the first time. At $T = 100$, there is an important event in football match and we switch the channel for the second time. At $T = 200$, there is an important event in football match and since we are on the same channel, we don't switch. At $T = 300$, there is an important event in football match and since we are on the same channel, we don't switch. So in total we switch two times.
Case 3: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are on the same channel, we don't switch. At $T = 100$, there is an important event in cricket match and we switch the channel for the first time. At $T = 200$, there is an important event in cricket match and since we are on the same channel, we don't switch. So in total we switch only one time.
|
for _ in range(int(input())):
n, m = list(map(int, input().split()))
foot = list(map(int, input().split()))
cric = list(map(int, input().split()))
start = 0
ch = 0
ans = 0
i, j = 0, 0
while i < n and j < m:
if foot[i] < cric[j]:
if ch == 1:
ans += 1
i += 1
ch = 0
else:
if ch == 0:
ans += 1
j += 1
ch = 1
if i < n and ch == 1:
ans += 1
elif j < m and ch == 0:
ans += 1
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There is only $1$ TV in the common room, and as luck would have it, both the El Clasico football match and the India-Pakistan cricket match are happening simultaneously.
There is one football fan who is looking at the live commentary online and will scream whenever an 'important' event takes place in the El Clasico. Similarly, there is a cricket fan who will do so for every important event in the cricket match.
You are given two arrays - $F_{1}, F_{2}, \ldots, F_{n}$, which denote the times when an important event happens in the football match. And similarly $C_{1}, C_{2}, \ldots, C_{m}$ for cricket.
You sadly have the remote in hand. You start out by watching the El Clasico. But whenever an Important event happens in the sport which isn't on the TV right now, you will be forced to switch to that sport's channel, and this continues, i.e., you switch channels if and only if when an important event in the other sport happens.
Find the total number of times you will have to switch between the channels.
------ Input: ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of $3$ lines of input.
First line contain $2$ space separated integers $N$ and $M$, number of important events in football and cricket match respectively.
Second line contain $N$ space separated integers $F_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the football match.
Third line contain $M$ space separated integers $C_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the cricket match.
------ Output: ------
For each testcase, output in a single line answer to the problem.
------ Constraints ------
$1 ≤ N, M ≤ 2.5*10^{4}$
$1 ≤ F_{i}, C_{i} ≤ 10^{9}$
$F_{i} > F_{i - 1}$ $\forall i > 0$
$C_{i} > C_{i - 1}$ $\forall i > 0$
$F_{i}$ != $C_{j}$ $\forall i, j$
Sum of $N$ over all tests is atmost $2*10^{5}$
Sum of $M$ over all tests is atmost $2*10^{5}$
----- Sample Input 1 ------
3
2 2
1 3
2 4
3 1
100 200 300
1
1 2
1
100 200
----- Sample Output 1 ------
3
2
1
----- explanation 1 ------
Case 1: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are already watching the same channel we won't switch. At $T = 2$,
there is an important event in cricket match and we switch the channel for the first time. At $T = 3$, there is an important event in football match and we switch the channel for the second time. At $T = 4$, there is an important event in cricket match and we switch the channel for the third time. So in total we switch three times.
Case 2: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in cricket match and we switch the channel for the first time. At $T = 100$, there is an important event in football match and we switch the channel for the second time. At $T = 200$, there is an important event in football match and since we are on the same channel, we don't switch. At $T = 300$, there is an important event in football match and since we are on the same channel, we don't switch. So in total we switch two times.
Case 3: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are on the same channel, we don't switch. At $T = 100$, there is an important event in cricket match and we switch the channel for the first time. At $T = 200$, there is an important event in cricket match and since we are on the same channel, we don't switch. So in total we switch only one time.
|
t = int(input())
for i in range(t):
n = list(map(int, input().split()))
f = list(map(int, input().split()))
c = list(map(int, input().split()))
d = {}
ft = 0
for i in f:
d[i] = 0
for i in c:
d[i] = 1
l = list(d.keys())
l.sort()
count = 0
for i in l:
if d[i] == ft:
pass
else:
count += 1
ft = d[i]
print(count)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
There is only $1$ TV in the common room, and as luck would have it, both the El Clasico football match and the India-Pakistan cricket match are happening simultaneously.
There is one football fan who is looking at the live commentary online and will scream whenever an 'important' event takes place in the El Clasico. Similarly, there is a cricket fan who will do so for every important event in the cricket match.
You are given two arrays - $F_{1}, F_{2}, \ldots, F_{n}$, which denote the times when an important event happens in the football match. And similarly $C_{1}, C_{2}, \ldots, C_{m}$ for cricket.
You sadly have the remote in hand. You start out by watching the El Clasico. But whenever an Important event happens in the sport which isn't on the TV right now, you will be forced to switch to that sport's channel, and this continues, i.e., you switch channels if and only if when an important event in the other sport happens.
Find the total number of times you will have to switch between the channels.
------ Input: ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of $3$ lines of input.
First line contain $2$ space separated integers $N$ and $M$, number of important events in football and cricket match respectively.
Second line contain $N$ space separated integers $F_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the football match.
Third line contain $M$ space separated integers $C_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the cricket match.
------ Output: ------
For each testcase, output in a single line answer to the problem.
------ Constraints ------
$1 ≤ N, M ≤ 2.5*10^{4}$
$1 ≤ F_{i}, C_{i} ≤ 10^{9}$
$F_{i} > F_{i - 1}$ $\forall i > 0$
$C_{i} > C_{i - 1}$ $\forall i > 0$
$F_{i}$ != $C_{j}$ $\forall i, j$
Sum of $N$ over all tests is atmost $2*10^{5}$
Sum of $M$ over all tests is atmost $2*10^{5}$
----- Sample Input 1 ------
3
2 2
1 3
2 4
3 1
100 200 300
1
1 2
1
100 200
----- Sample Output 1 ------
3
2
1
----- explanation 1 ------
Case 1: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are already watching the same channel we won't switch. At $T = 2$,
there is an important event in cricket match and we switch the channel for the first time. At $T = 3$, there is an important event in football match and we switch the channel for the second time. At $T = 4$, there is an important event in cricket match and we switch the channel for the third time. So in total we switch three times.
Case 2: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in cricket match and we switch the channel for the first time. At $T = 100$, there is an important event in football match and we switch the channel for the second time. At $T = 200$, there is an important event in football match and since we are on the same channel, we don't switch. At $T = 300$, there is an important event in football match and since we are on the same channel, we don't switch. So in total we switch two times.
Case 3: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are on the same channel, we don't switch. At $T = 100$, there is an important event in cricket match and we switch the channel for the first time. At $T = 200$, there is an important event in cricket match and since we are on the same channel, we don't switch. So in total we switch only one time.
|
t = int(input())
while t:
t -= 1
n, m = map(int, input().split())
ftb = list(map(int, input().split()))
crc = list(map(int, input().split()))
d = {}
count = 0
for i in range(n):
d[ftb[i]] = "f"
for i in range(m):
d[crc[i]] = "c"
d = dict(sorted(d.items(), key=lambda x: x[0]))
temp = "f"
dkeys = list(d.keys())
for i in range(len(d)):
if d[dkeys[i]] != temp:
count += 1
temp = d[dkeys[i]]
print(count)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
There is only $1$ TV in the common room, and as luck would have it, both the El Clasico football match and the India-Pakistan cricket match are happening simultaneously.
There is one football fan who is looking at the live commentary online and will scream whenever an 'important' event takes place in the El Clasico. Similarly, there is a cricket fan who will do so for every important event in the cricket match.
You are given two arrays - $F_{1}, F_{2}, \ldots, F_{n}$, which denote the times when an important event happens in the football match. And similarly $C_{1}, C_{2}, \ldots, C_{m}$ for cricket.
You sadly have the remote in hand. You start out by watching the El Clasico. But whenever an Important event happens in the sport which isn't on the TV right now, you will be forced to switch to that sport's channel, and this continues, i.e., you switch channels if and only if when an important event in the other sport happens.
Find the total number of times you will have to switch between the channels.
------ Input: ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of $3$ lines of input.
First line contain $2$ space separated integers $N$ and $M$, number of important events in football and cricket match respectively.
Second line contain $N$ space separated integers $F_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the football match.
Third line contain $M$ space separated integers $C_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the cricket match.
------ Output: ------
For each testcase, output in a single line answer to the problem.
------ Constraints ------
$1 ≤ N, M ≤ 2.5*10^{4}$
$1 ≤ F_{i}, C_{i} ≤ 10^{9}$
$F_{i} > F_{i - 1}$ $\forall i > 0$
$C_{i} > C_{i - 1}$ $\forall i > 0$
$F_{i}$ != $C_{j}$ $\forall i, j$
Sum of $N$ over all tests is atmost $2*10^{5}$
Sum of $M$ over all tests is atmost $2*10^{5}$
----- Sample Input 1 ------
3
2 2
1 3
2 4
3 1
100 200 300
1
1 2
1
100 200
----- Sample Output 1 ------
3
2
1
----- explanation 1 ------
Case 1: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are already watching the same channel we won't switch. At $T = 2$,
there is an important event in cricket match and we switch the channel for the first time. At $T = 3$, there is an important event in football match and we switch the channel for the second time. At $T = 4$, there is an important event in cricket match and we switch the channel for the third time. So in total we switch three times.
Case 2: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in cricket match and we switch the channel for the first time. At $T = 100$, there is an important event in football match and we switch the channel for the second time. At $T = 200$, there is an important event in football match and since we are on the same channel, we don't switch. At $T = 300$, there is an important event in football match and since we are on the same channel, we don't switch. So in total we switch two times.
Case 3: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are on the same channel, we don't switch. At $T = 100$, there is an important event in cricket match and we switch the channel for the first time. At $T = 200$, there is an important event in cricket match and since we are on the same channel, we don't switch. So in total we switch only one time.
|
for _ in range(int(input())):
n, m = map(int, input().split())
f, c, pf, pc, prev = (
list(map(int, input().split())),
list(map(int, input().split())),
[(0) for _ in range(0, n)],
[(1) for _ in range(0, m)],
0,
)
xf, xc = dict(zip(f, pf)), dict(zip(c, pc))
xc.update(xf)
y, x = sorted(f + c), 0
for i in y:
if xc[i] != prev:
x, prev = x + 1, xc[i]
print(x)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
There is only $1$ TV in the common room, and as luck would have it, both the El Clasico football match and the India-Pakistan cricket match are happening simultaneously.
There is one football fan who is looking at the live commentary online and will scream whenever an 'important' event takes place in the El Clasico. Similarly, there is a cricket fan who will do so for every important event in the cricket match.
You are given two arrays - $F_{1}, F_{2}, \ldots, F_{n}$, which denote the times when an important event happens in the football match. And similarly $C_{1}, C_{2}, \ldots, C_{m}$ for cricket.
You sadly have the remote in hand. You start out by watching the El Clasico. But whenever an Important event happens in the sport which isn't on the TV right now, you will be forced to switch to that sport's channel, and this continues, i.e., you switch channels if and only if when an important event in the other sport happens.
Find the total number of times you will have to switch between the channels.
------ Input: ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of $3$ lines of input.
First line contain $2$ space separated integers $N$ and $M$, number of important events in football and cricket match respectively.
Second line contain $N$ space separated integers $F_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the football match.
Third line contain $M$ space separated integers $C_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the cricket match.
------ Output: ------
For each testcase, output in a single line answer to the problem.
------ Constraints ------
$1 ≤ N, M ≤ 2.5*10^{4}$
$1 ≤ F_{i}, C_{i} ≤ 10^{9}$
$F_{i} > F_{i - 1}$ $\forall i > 0$
$C_{i} > C_{i - 1}$ $\forall i > 0$
$F_{i}$ != $C_{j}$ $\forall i, j$
Sum of $N$ over all tests is atmost $2*10^{5}$
Sum of $M$ over all tests is atmost $2*10^{5}$
----- Sample Input 1 ------
3
2 2
1 3
2 4
3 1
100 200 300
1
1 2
1
100 200
----- Sample Output 1 ------
3
2
1
----- explanation 1 ------
Case 1: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are already watching the same channel we won't switch. At $T = 2$,
there is an important event in cricket match and we switch the channel for the first time. At $T = 3$, there is an important event in football match and we switch the channel for the second time. At $T = 4$, there is an important event in cricket match and we switch the channel for the third time. So in total we switch three times.
Case 2: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in cricket match and we switch the channel for the first time. At $T = 100$, there is an important event in football match and we switch the channel for the second time. At $T = 200$, there is an important event in football match and since we are on the same channel, we don't switch. At $T = 300$, there is an important event in football match and since we are on the same channel, we don't switch. So in total we switch two times.
Case 3: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are on the same channel, we don't switch. At $T = 100$, there is an important event in cricket match and we switch the channel for the first time. At $T = 200$, there is an important event in cricket match and since we are on the same channel, we don't switch. So in total we switch only one time.
|
t = int(input())
for _ in range(t):
n, m = map(int, input().split())
f = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = 0
if f[0] < c[0]:
curr = 0
i = 1
j = 0
else:
ans += 1
curr = 1
i = 0
j = 1
while i < n and j < m:
if f[i] < c[j]:
if curr == 1:
ans += 1
curr = 0
i += 1
elif c[j] < f[i]:
if curr == 0:
ans += 1
curr = 1
j += 1
if i < n:
if curr == 1:
ans += 1
elif curr == 0:
ans += 1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There is only $1$ TV in the common room, and as luck would have it, both the El Clasico football match and the India-Pakistan cricket match are happening simultaneously.
There is one football fan who is looking at the live commentary online and will scream whenever an 'important' event takes place in the El Clasico. Similarly, there is a cricket fan who will do so for every important event in the cricket match.
You are given two arrays - $F_{1}, F_{2}, \ldots, F_{n}$, which denote the times when an important event happens in the football match. And similarly $C_{1}, C_{2}, \ldots, C_{m}$ for cricket.
You sadly have the remote in hand. You start out by watching the El Clasico. But whenever an Important event happens in the sport which isn't on the TV right now, you will be forced to switch to that sport's channel, and this continues, i.e., you switch channels if and only if when an important event in the other sport happens.
Find the total number of times you will have to switch between the channels.
------ Input: ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of $3$ lines of input.
First line contain $2$ space separated integers $N$ and $M$, number of important events in football and cricket match respectively.
Second line contain $N$ space separated integers $F_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the football match.
Third line contain $M$ space separated integers $C_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the cricket match.
------ Output: ------
For each testcase, output in a single line answer to the problem.
------ Constraints ------
$1 ≤ N, M ≤ 2.5*10^{4}$
$1 ≤ F_{i}, C_{i} ≤ 10^{9}$
$F_{i} > F_{i - 1}$ $\forall i > 0$
$C_{i} > C_{i - 1}$ $\forall i > 0$
$F_{i}$ != $C_{j}$ $\forall i, j$
Sum of $N$ over all tests is atmost $2*10^{5}$
Sum of $M$ over all tests is atmost $2*10^{5}$
----- Sample Input 1 ------
3
2 2
1 3
2 4
3 1
100 200 300
1
1 2
1
100 200
----- Sample Output 1 ------
3
2
1
----- explanation 1 ------
Case 1: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are already watching the same channel we won't switch. At $T = 2$,
there is an important event in cricket match and we switch the channel for the first time. At $T = 3$, there is an important event in football match and we switch the channel for the second time. At $T = 4$, there is an important event in cricket match and we switch the channel for the third time. So in total we switch three times.
Case 2: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in cricket match and we switch the channel for the first time. At $T = 100$, there is an important event in football match and we switch the channel for the second time. At $T = 200$, there is an important event in football match and since we are on the same channel, we don't switch. At $T = 300$, there is an important event in football match and since we are on the same channel, we don't switch. So in total we switch two times.
Case 3: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are on the same channel, we don't switch. At $T = 100$, there is an important event in cricket match and we switch the channel for the first time. At $T = 200$, there is an important event in cricket match and since we are on the same channel, we don't switch. So in total we switch only one time.
|
def solve(n, m, football, cricket):
switches = 0
football_bool = True
f_index = 0
c_index = 0
while f_index < n and c_index < m:
if football[f_index] < cricket[c_index]:
if not football_bool:
switches += 1
football_bool = True
f_index += 1
else:
if football_bool:
switches += 1
c_index += 1
football_bool = False
if f_index < n and not football_bool or c_index < m and football_bool:
switches += 1
return switches
def main():
for _ in range(int(input())):
n, m = map(int, input().split())
football = list(map(int, input().split()))
cricket = list(map(int, input().split()))
print(solve(n, m, football, cricket))
main()
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR
|
There is only $1$ TV in the common room, and as luck would have it, both the El Clasico football match and the India-Pakistan cricket match are happening simultaneously.
There is one football fan who is looking at the live commentary online and will scream whenever an 'important' event takes place in the El Clasico. Similarly, there is a cricket fan who will do so for every important event in the cricket match.
You are given two arrays - $F_{1}, F_{2}, \ldots, F_{n}$, which denote the times when an important event happens in the football match. And similarly $C_{1}, C_{2}, \ldots, C_{m}$ for cricket.
You sadly have the remote in hand. You start out by watching the El Clasico. But whenever an Important event happens in the sport which isn't on the TV right now, you will be forced to switch to that sport's channel, and this continues, i.e., you switch channels if and only if when an important event in the other sport happens.
Find the total number of times you will have to switch between the channels.
------ Input: ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of $3$ lines of input.
First line contain $2$ space separated integers $N$ and $M$, number of important events in football and cricket match respectively.
Second line contain $N$ space separated integers $F_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the football match.
Third line contain $M$ space separated integers $C_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the cricket match.
------ Output: ------
For each testcase, output in a single line answer to the problem.
------ Constraints ------
$1 ≤ N, M ≤ 2.5*10^{4}$
$1 ≤ F_{i}, C_{i} ≤ 10^{9}$
$F_{i} > F_{i - 1}$ $\forall i > 0$
$C_{i} > C_{i - 1}$ $\forall i > 0$
$F_{i}$ != $C_{j}$ $\forall i, j$
Sum of $N$ over all tests is atmost $2*10^{5}$
Sum of $M$ over all tests is atmost $2*10^{5}$
----- Sample Input 1 ------
3
2 2
1 3
2 4
3 1
100 200 300
1
1 2
1
100 200
----- Sample Output 1 ------
3
2
1
----- explanation 1 ------
Case 1: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are already watching the same channel we won't switch. At $T = 2$,
there is an important event in cricket match and we switch the channel for the first time. At $T = 3$, there is an important event in football match and we switch the channel for the second time. At $T = 4$, there is an important event in cricket match and we switch the channel for the third time. So in total we switch three times.
Case 2: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in cricket match and we switch the channel for the first time. At $T = 100$, there is an important event in football match and we switch the channel for the second time. At $T = 200$, there is an important event in football match and since we are on the same channel, we don't switch. At $T = 300$, there is an important event in football match and since we are on the same channel, we don't switch. So in total we switch two times.
Case 3: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are on the same channel, we don't switch. At $T = 100$, there is an important event in cricket match and we switch the channel for the first time. At $T = 200$, there is an important event in cricket match and since we are on the same channel, we don't switch. So in total we switch only one time.
|
t = int(input())
for i in range(t):
n, m = map(int, input().split())
f = list(map(lambda x: 2 * int(x), input().split()))
c = list(map(lambda x: 2 * int(x) + 1, input().split()))
fc = sorted(f + c, key=int)
k = 0
c = 0
for j in fc:
if (j - k) % 2 == 1:
c += 1
k = j
print(c)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
There is only $1$ TV in the common room, and as luck would have it, both the El Clasico football match and the India-Pakistan cricket match are happening simultaneously.
There is one football fan who is looking at the live commentary online and will scream whenever an 'important' event takes place in the El Clasico. Similarly, there is a cricket fan who will do so for every important event in the cricket match.
You are given two arrays - $F_{1}, F_{2}, \ldots, F_{n}$, which denote the times when an important event happens in the football match. And similarly $C_{1}, C_{2}, \ldots, C_{m}$ for cricket.
You sadly have the remote in hand. You start out by watching the El Clasico. But whenever an Important event happens in the sport which isn't on the TV right now, you will be forced to switch to that sport's channel, and this continues, i.e., you switch channels if and only if when an important event in the other sport happens.
Find the total number of times you will have to switch between the channels.
------ Input: ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of $3$ lines of input.
First line contain $2$ space separated integers $N$ and $M$, number of important events in football and cricket match respectively.
Second line contain $N$ space separated integers $F_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the football match.
Third line contain $M$ space separated integers $C_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the cricket match.
------ Output: ------
For each testcase, output in a single line answer to the problem.
------ Constraints ------
$1 ≤ N, M ≤ 2.5*10^{4}$
$1 ≤ F_{i}, C_{i} ≤ 10^{9}$
$F_{i} > F_{i - 1}$ $\forall i > 0$
$C_{i} > C_{i - 1}$ $\forall i > 0$
$F_{i}$ != $C_{j}$ $\forall i, j$
Sum of $N$ over all tests is atmost $2*10^{5}$
Sum of $M$ over all tests is atmost $2*10^{5}$
----- Sample Input 1 ------
3
2 2
1 3
2 4
3 1
100 200 300
1
1 2
1
100 200
----- Sample Output 1 ------
3
2
1
----- explanation 1 ------
Case 1: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are already watching the same channel we won't switch. At $T = 2$,
there is an important event in cricket match and we switch the channel for the first time. At $T = 3$, there is an important event in football match and we switch the channel for the second time. At $T = 4$, there is an important event in cricket match and we switch the channel for the third time. So in total we switch three times.
Case 2: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in cricket match and we switch the channel for the first time. At $T = 100$, there is an important event in football match and we switch the channel for the second time. At $T = 200$, there is an important event in football match and since we are on the same channel, we don't switch. At $T = 300$, there is an important event in football match and since we are on the same channel, we don't switch. So in total we switch two times.
Case 3: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are on the same channel, we don't switch. At $T = 100$, there is an important event in cricket match and we switch the channel for the first time. At $T = 200$, there is an important event in cricket match and since we are on the same channel, we don't switch. So in total we switch only one time.
|
for T in range(int(input())):
N, M = map(int, input().split())
F = list(map(int, input().split()))
C = list(map(int, input().split()))
Channel = "F"
result = 0
for i in range(int(N + M)):
if len(F) != 0 and len(C) != 0:
if F[0] < C[0]:
del F[0]
if Channel != "F":
result += 1
Channel = "F"
else:
del C[0]
if Channel != "C":
result += 1
Channel = "C"
else:
result += 1
break
print(result)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR STRING VAR NUMBER ASSIGN VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER ASSIGN VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There is only $1$ TV in the common room, and as luck would have it, both the El Clasico football match and the India-Pakistan cricket match are happening simultaneously.
There is one football fan who is looking at the live commentary online and will scream whenever an 'important' event takes place in the El Clasico. Similarly, there is a cricket fan who will do so for every important event in the cricket match.
You are given two arrays - $F_{1}, F_{2}, \ldots, F_{n}$, which denote the times when an important event happens in the football match. And similarly $C_{1}, C_{2}, \ldots, C_{m}$ for cricket.
You sadly have the remote in hand. You start out by watching the El Clasico. But whenever an Important event happens in the sport which isn't on the TV right now, you will be forced to switch to that sport's channel, and this continues, i.e., you switch channels if and only if when an important event in the other sport happens.
Find the total number of times you will have to switch between the channels.
------ Input: ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of $3$ lines of input.
First line contain $2$ space separated integers $N$ and $M$, number of important events in football and cricket match respectively.
Second line contain $N$ space separated integers $F_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the football match.
Third line contain $M$ space separated integers $C_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the cricket match.
------ Output: ------
For each testcase, output in a single line answer to the problem.
------ Constraints ------
$1 ≤ N, M ≤ 2.5*10^{4}$
$1 ≤ F_{i}, C_{i} ≤ 10^{9}$
$F_{i} > F_{i - 1}$ $\forall i > 0$
$C_{i} > C_{i - 1}$ $\forall i > 0$
$F_{i}$ != $C_{j}$ $\forall i, j$
Sum of $N$ over all tests is atmost $2*10^{5}$
Sum of $M$ over all tests is atmost $2*10^{5}$
----- Sample Input 1 ------
3
2 2
1 3
2 4
3 1
100 200 300
1
1 2
1
100 200
----- Sample Output 1 ------
3
2
1
----- explanation 1 ------
Case 1: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are already watching the same channel we won't switch. At $T = 2$,
there is an important event in cricket match and we switch the channel for the first time. At $T = 3$, there is an important event in football match and we switch the channel for the second time. At $T = 4$, there is an important event in cricket match and we switch the channel for the third time. So in total we switch three times.
Case 2: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in cricket match and we switch the channel for the first time. At $T = 100$, there is an important event in football match and we switch the channel for the second time. At $T = 200$, there is an important event in football match and since we are on the same channel, we don't switch. At $T = 300$, there is an important event in football match and since we are on the same channel, we don't switch. So in total we switch two times.
Case 3: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are on the same channel, we don't switch. At $T = 100$, there is an important event in cricket match and we switch the channel for the first time. At $T = 200$, there is an important event in cricket match and since we are on the same channel, we don't switch. So in total we switch only one time.
|
from sys import stdin
input = stdin.readline
for _ in range(int(input())):
n, m = map(int, input().split())
fli = list(map(int, input().split()))
cli = list(map(int, input().split()))
lst = list()
lst.append([0, 1])
for a in fli:
lst.append([a, 1])
for b in cli:
lst.append([b, 2])
lst.sort()
cnt = 0
for i in range(1, len(lst)):
if lst[i][1] != lst[i - 1][1]:
cnt += 1
print(cnt)
|
ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST NUMBER NUMBER FOR VAR VAR EXPR FUNC_CALL VAR LIST VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR LIST VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There is only $1$ TV in the common room, and as luck would have it, both the El Clasico football match and the India-Pakistan cricket match are happening simultaneously.
There is one football fan who is looking at the live commentary online and will scream whenever an 'important' event takes place in the El Clasico. Similarly, there is a cricket fan who will do so for every important event in the cricket match.
You are given two arrays - $F_{1}, F_{2}, \ldots, F_{n}$, which denote the times when an important event happens in the football match. And similarly $C_{1}, C_{2}, \ldots, C_{m}$ for cricket.
You sadly have the remote in hand. You start out by watching the El Clasico. But whenever an Important event happens in the sport which isn't on the TV right now, you will be forced to switch to that sport's channel, and this continues, i.e., you switch channels if and only if when an important event in the other sport happens.
Find the total number of times you will have to switch between the channels.
------ Input: ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of $3$ lines of input.
First line contain $2$ space separated integers $N$ and $M$, number of important events in football and cricket match respectively.
Second line contain $N$ space separated integers $F_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the football match.
Third line contain $M$ space separated integers $C_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the cricket match.
------ Output: ------
For each testcase, output in a single line answer to the problem.
------ Constraints ------
$1 ≤ N, M ≤ 2.5*10^{4}$
$1 ≤ F_{i}, C_{i} ≤ 10^{9}$
$F_{i} > F_{i - 1}$ $\forall i > 0$
$C_{i} > C_{i - 1}$ $\forall i > 0$
$F_{i}$ != $C_{j}$ $\forall i, j$
Sum of $N$ over all tests is atmost $2*10^{5}$
Sum of $M$ over all tests is atmost $2*10^{5}$
----- Sample Input 1 ------
3
2 2
1 3
2 4
3 1
100 200 300
1
1 2
1
100 200
----- Sample Output 1 ------
3
2
1
----- explanation 1 ------
Case 1: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are already watching the same channel we won't switch. At $T = 2$,
there is an important event in cricket match and we switch the channel for the first time. At $T = 3$, there is an important event in football match and we switch the channel for the second time. At $T = 4$, there is an important event in cricket match and we switch the channel for the third time. So in total we switch three times.
Case 2: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in cricket match and we switch the channel for the first time. At $T = 100$, there is an important event in football match and we switch the channel for the second time. At $T = 200$, there is an important event in football match and since we are on the same channel, we don't switch. At $T = 300$, there is an important event in football match and since we are on the same channel, we don't switch. So in total we switch two times.
Case 3: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are on the same channel, we don't switch. At $T = 100$, there is an important event in cricket match and we switch the channel for the first time. At $T = 200$, there is an important event in cricket match and since we are on the same channel, we don't switch. So in total we switch only one time.
|
t = int(input())
while t != 0:
n, m = list(map(int, input().split()))
f = list(map(int, input().split()))
c = list(map(int, input().split()))
fd = list(map(lambda x: (x, "f"), f))
cd = list(map(lambda x: (x, "c"), c))
main = fd + cd
main.sort()
toSwitch = "c"
switches = 0
for i in range(len(main)):
if toSwitch == main[i][1]:
switches = switches + 1
if toSwitch == "c":
toSwitch = "f"
else:
toSwitch = "c"
print(switches)
t = t - 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER
|
There is only $1$ TV in the common room, and as luck would have it, both the El Clasico football match and the India-Pakistan cricket match are happening simultaneously.
There is one football fan who is looking at the live commentary online and will scream whenever an 'important' event takes place in the El Clasico. Similarly, there is a cricket fan who will do so for every important event in the cricket match.
You are given two arrays - $F_{1}, F_{2}, \ldots, F_{n}$, which denote the times when an important event happens in the football match. And similarly $C_{1}, C_{2}, \ldots, C_{m}$ for cricket.
You sadly have the remote in hand. You start out by watching the El Clasico. But whenever an Important event happens in the sport which isn't on the TV right now, you will be forced to switch to that sport's channel, and this continues, i.e., you switch channels if and only if when an important event in the other sport happens.
Find the total number of times you will have to switch between the channels.
------ Input: ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of $3$ lines of input.
First line contain $2$ space separated integers $N$ and $M$, number of important events in football and cricket match respectively.
Second line contain $N$ space separated integers $F_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the football match.
Third line contain $M$ space separated integers $C_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the cricket match.
------ Output: ------
For each testcase, output in a single line answer to the problem.
------ Constraints ------
$1 ≤ N, M ≤ 2.5*10^{4}$
$1 ≤ F_{i}, C_{i} ≤ 10^{9}$
$F_{i} > F_{i - 1}$ $\forall i > 0$
$C_{i} > C_{i - 1}$ $\forall i > 0$
$F_{i}$ != $C_{j}$ $\forall i, j$
Sum of $N$ over all tests is atmost $2*10^{5}$
Sum of $M$ over all tests is atmost $2*10^{5}$
----- Sample Input 1 ------
3
2 2
1 3
2 4
3 1
100 200 300
1
1 2
1
100 200
----- Sample Output 1 ------
3
2
1
----- explanation 1 ------
Case 1: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are already watching the same channel we won't switch. At $T = 2$,
there is an important event in cricket match and we switch the channel for the first time. At $T = 3$, there is an important event in football match and we switch the channel for the second time. At $T = 4$, there is an important event in cricket match and we switch the channel for the third time. So in total we switch three times.
Case 2: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in cricket match and we switch the channel for the first time. At $T = 100$, there is an important event in football match and we switch the channel for the second time. At $T = 200$, there is an important event in football match and since we are on the same channel, we don't switch. At $T = 300$, there is an important event in football match and since we are on the same channel, we don't switch. So in total we switch two times.
Case 3: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are on the same channel, we don't switch. At $T = 100$, there is an important event in cricket match and we switch the channel for the first time. At $T = 200$, there is an important event in cricket match and since we are on the same channel, we don't switch. So in total we switch only one time.
|
for i in range(int(input())):
n, m = map(int, input().split())
l = list(map(int, input().split()))
t = list(map(int, input().split()))
d = {}
for j in l:
d[j] = 0
for j in t:
d[j] = 1
c = 0
f = 0
for j in sorted(d.keys()):
if d[j] == 0 and f == 1:
f = 0
c = c + 1
if d[j] == 1 and f == 0:
f = 1
c = c + 1
print(c)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There is only $1$ TV in the common room, and as luck would have it, both the El Clasico football match and the India-Pakistan cricket match are happening simultaneously.
There is one football fan who is looking at the live commentary online and will scream whenever an 'important' event takes place in the El Clasico. Similarly, there is a cricket fan who will do so for every important event in the cricket match.
You are given two arrays - $F_{1}, F_{2}, \ldots, F_{n}$, which denote the times when an important event happens in the football match. And similarly $C_{1}, C_{2}, \ldots, C_{m}$ for cricket.
You sadly have the remote in hand. You start out by watching the El Clasico. But whenever an Important event happens in the sport which isn't on the TV right now, you will be forced to switch to that sport's channel, and this continues, i.e., you switch channels if and only if when an important event in the other sport happens.
Find the total number of times you will have to switch between the channels.
------ Input: ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of $3$ lines of input.
First line contain $2$ space separated integers $N$ and $M$, number of important events in football and cricket match respectively.
Second line contain $N$ space separated integers $F_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the football match.
Third line contain $M$ space separated integers $C_{i}$, where the $i^{th}$ index represents $i^{th}$ important event in the cricket match.
------ Output: ------
For each testcase, output in a single line answer to the problem.
------ Constraints ------
$1 ≤ N, M ≤ 2.5*10^{4}$
$1 ≤ F_{i}, C_{i} ≤ 10^{9}$
$F_{i} > F_{i - 1}$ $\forall i > 0$
$C_{i} > C_{i - 1}$ $\forall i > 0$
$F_{i}$ != $C_{j}$ $\forall i, j$
Sum of $N$ over all tests is atmost $2*10^{5}$
Sum of $M$ over all tests is atmost $2*10^{5}$
----- Sample Input 1 ------
3
2 2
1 3
2 4
3 1
100 200 300
1
1 2
1
100 200
----- Sample Output 1 ------
3
2
1
----- explanation 1 ------
Case 1: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are already watching the same channel we won't switch. At $T = 2$,
there is an important event in cricket match and we switch the channel for the first time. At $T = 3$, there is an important event in football match and we switch the channel for the second time. At $T = 4$, there is an important event in cricket match and we switch the channel for the third time. So in total we switch three times.
Case 2: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in cricket match and we switch the channel for the first time. At $T = 100$, there is an important event in football match and we switch the channel for the second time. At $T = 200$, there is an important event in football match and since we are on the same channel, we don't switch. At $T = 300$, there is an important event in football match and since we are on the same channel, we don't switch. So in total we switch two times.
Case 3: At $T = 0$, we are watching El Clasico. At $T = 1$ there is an important event in football match and since we are on the same channel, we don't switch. At $T = 100$, there is an important event in cricket match and we switch the channel for the first time. At $T = 200$, there is an important event in cricket match and since we are on the same channel, we don't switch. So in total we switch only one time.
|
t = int(input())
for i in range(t):
n, m = map(int, input().split())
f = list(map(int, input().split()))
c = list(map(int, input().split()))
i = 0
j = 0
curr = "F"
res = 0
while i < n and j < m:
if f[i] < c[j]:
if curr == "C":
res += 1
curr = "F"
i += 1
elif f[i] == c[j]:
if curr == "C":
res += 1
curr = "F"
elif curr == "F":
res += 1
curr = "C"
i += 1
j += 1
else:
if curr == "F":
res += 1
curr = "C"
j += 1
if i < n:
if curr == "C":
res += 1
if j < m:
if curr == "F":
res += 1
print(res)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR IF VAR STRING VAR NUMBER ASSIGN VAR STRING VAR NUMBER IF VAR VAR VAR VAR IF VAR STRING VAR NUMBER ASSIGN VAR STRING IF VAR STRING VAR NUMBER ASSIGN VAR STRING VAR NUMBER VAR NUMBER IF VAR STRING VAR NUMBER ASSIGN VAR STRING VAR NUMBER IF VAR VAR IF VAR STRING VAR NUMBER IF VAR VAR IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR
|
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers.
If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} K ⌉ bits to store each value. It then takes nk bits to store the whole file.
To reduce the memory consumption we need to apply some compression. One common way is to reduce the number of possible intensity values. We choose two integers l ≤ r, and after that all intensity values are changed in the following way: if the intensity value is within the range [l;r], we don't change it. If it is less than l, we change it to l; if it is greater than r, we change it to r. You can see that we lose some low and some high intensities.
Your task is to apply this compression in such a way that the file fits onto a disk of size I bytes, and the number of changed elements in the array is minimal possible.
We remind you that 1 byte contains 8 bits.
k = ⌈ log_{2} K ⌉ is the smallest integer such that K ≤ 2^{k}. In particular, if K = 1, then k = 0.
Input
The first line contains two integers n and I (1 ≤ n ≤ 4 ⋅ 10^{5}, 1 ≤ I ≤ 10^{8}) — the length of the array and the size of the disk in bytes, respectively.
The next line contains n integers a_{i} (0 ≤ a_{i} ≤ 10^{9}) — the array denoting the sound file.
Output
Print a single integer — the minimal possible number of changed elements.
Examples
Input
6 1
2 1 2 3 4 3
Output
2
Input
6 2
2 1 2 3 4 3
Output
0
Input
6 1
1 1 2 2 3 3
Output
2
Note
In the first example we can choose l=2, r=3. The array becomes 2 2 2 3 3 3, the number of distinct elements is K=2, and the sound file fits onto the disk. Only two values are changed.
In the second example the disk is larger, so the initial file fits it and no changes are required.
In the third example we have to change both 1s or both 3s.
|
from sys import setrecursionlimit as SRL
from sys import stdin
SRL(10**7)
rd = stdin.readline
rrd = lambda: map(int, rd().strip().split())
n, i = rrd()
i *= 8
can = 2 ** (i // n)
a = list(rrd())
a.sort()
a = [-1] + a + [-1]
ans = 10**100
j = 1
cnt = 0
for i in range(n + 1):
if i and a[i] != a[i - 1]:
cnt += 1
if cnt > can:
ans = min(ans, n - (i - j))
j += 1
while a[j] == a[j - 1]:
j += 1
cnt -= 1
ans = min(ans, n - (i + 1 - j))
print(ans)
|
EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR LIST NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
|
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers.
If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} K ⌉ bits to store each value. It then takes nk bits to store the whole file.
To reduce the memory consumption we need to apply some compression. One common way is to reduce the number of possible intensity values. We choose two integers l ≤ r, and after that all intensity values are changed in the following way: if the intensity value is within the range [l;r], we don't change it. If it is less than l, we change it to l; if it is greater than r, we change it to r. You can see that we lose some low and some high intensities.
Your task is to apply this compression in such a way that the file fits onto a disk of size I bytes, and the number of changed elements in the array is minimal possible.
We remind you that 1 byte contains 8 bits.
k = ⌈ log_{2} K ⌉ is the smallest integer such that K ≤ 2^{k}. In particular, if K = 1, then k = 0.
Input
The first line contains two integers n and I (1 ≤ n ≤ 4 ⋅ 10^{5}, 1 ≤ I ≤ 10^{8}) — the length of the array and the size of the disk in bytes, respectively.
The next line contains n integers a_{i} (0 ≤ a_{i} ≤ 10^{9}) — the array denoting the sound file.
Output
Print a single integer — the minimal possible number of changed elements.
Examples
Input
6 1
2 1 2 3 4 3
Output
2
Input
6 2
2 1 2 3 4 3
Output
0
Input
6 1
1 1 2 2 3 3
Output
2
Note
In the first example we can choose l=2, r=3. The array becomes 2 2 2 3 3 3, the number of distinct elements is K=2, and the sound file fits onto the disk. Only two values are changed.
In the second example the disk is larger, so the initial file fits it and no changes are required.
In the third example we have to change both 1s or both 3s.
|
n, i = map(int, input().split(" "))
sound = list(map(int, input().split(" ")))
sound.sort()
limit = 2 ** (i * 8 // n)
l = [0]
for i in range(1, n):
if sound[i - 1] != sound[i]:
l.append(i)
if len(l) <= limit:
print("0")
else:
print(n - max(l[i + limit] - l[i] for i in range(len(l) - limit)))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
|
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers.
If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} K ⌉ bits to store each value. It then takes nk bits to store the whole file.
To reduce the memory consumption we need to apply some compression. One common way is to reduce the number of possible intensity values. We choose two integers l ≤ r, and after that all intensity values are changed in the following way: if the intensity value is within the range [l;r], we don't change it. If it is less than l, we change it to l; if it is greater than r, we change it to r. You can see that we lose some low and some high intensities.
Your task is to apply this compression in such a way that the file fits onto a disk of size I bytes, and the number of changed elements in the array is minimal possible.
We remind you that 1 byte contains 8 bits.
k = ⌈ log_{2} K ⌉ is the smallest integer such that K ≤ 2^{k}. In particular, if K = 1, then k = 0.
Input
The first line contains two integers n and I (1 ≤ n ≤ 4 ⋅ 10^{5}, 1 ≤ I ≤ 10^{8}) — the length of the array and the size of the disk in bytes, respectively.
The next line contains n integers a_{i} (0 ≤ a_{i} ≤ 10^{9}) — the array denoting the sound file.
Output
Print a single integer — the minimal possible number of changed elements.
Examples
Input
6 1
2 1 2 3 4 3
Output
2
Input
6 2
2 1 2 3 4 3
Output
0
Input
6 1
1 1 2 2 3 3
Output
2
Note
In the first example we can choose l=2, r=3. The array becomes 2 2 2 3 3 3, the number of distinct elements is K=2, and the sound file fits onto the disk. Only two values are changed.
In the second example the disk is larger, so the initial file fits it and no changes are required.
In the third example we have to change both 1s or both 3s.
|
n, I = map(int, input().split())
a = list(map(int, input().split()))
k = I * 8 // n
K = 2**k
a.sort()
A = [1]
j = 0
for i in range(1, n):
if a[i] == a[i - 1]:
A[j] += 1
else:
A.append(1)
j += 1
c = len(A) - K
s1 = sum(A[:c])
s2 = 0
if c <= 0:
ans = 0
else:
ans = 10**9 + 7
for i in range(c + 1):
ans = min(ans, s1 + s2)
s1 -= A[c - 1 - i]
s2 += A[len(A) - 1 - i]
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
|
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers.
If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} K ⌉ bits to store each value. It then takes nk bits to store the whole file.
To reduce the memory consumption we need to apply some compression. One common way is to reduce the number of possible intensity values. We choose two integers l ≤ r, and after that all intensity values are changed in the following way: if the intensity value is within the range [l;r], we don't change it. If it is less than l, we change it to l; if it is greater than r, we change it to r. You can see that we lose some low and some high intensities.
Your task is to apply this compression in such a way that the file fits onto a disk of size I bytes, and the number of changed elements in the array is minimal possible.
We remind you that 1 byte contains 8 bits.
k = ⌈ log_{2} K ⌉ is the smallest integer such that K ≤ 2^{k}. In particular, if K = 1, then k = 0.
Input
The first line contains two integers n and I (1 ≤ n ≤ 4 ⋅ 10^{5}, 1 ≤ I ≤ 10^{8}) — the length of the array and the size of the disk in bytes, respectively.
The next line contains n integers a_{i} (0 ≤ a_{i} ≤ 10^{9}) — the array denoting the sound file.
Output
Print a single integer — the minimal possible number of changed elements.
Examples
Input
6 1
2 1 2 3 4 3
Output
2
Input
6 2
2 1 2 3 4 3
Output
0
Input
6 1
1 1 2 2 3 3
Output
2
Note
In the first example we can choose l=2, r=3. The array becomes 2 2 2 3 3 3, the number of distinct elements is K=2, and the sound file fits onto the disk. Only two values are changed.
In the second example the disk is larger, so the initial file fits it and no changes are required.
In the third example we have to change both 1s or both 3s.
|
n, I = map(int, input().split())
audio_list = list(map(int, input().split()))
K = pow(2, 8 * I // n)
audio_dict = {}
for el in audio_list:
if el not in audio_dict:
audio_dict[el] = 1
else:
audio_dict[el] += 1
audio_keys = sorted(list(audio_dict.keys()))
audio = [audio_dict[el] for el in audio_keys]
if K >= len(audio):
print(0)
else:
count = len(audio) - K
result = temp = sum(audio[:count])
for i in range(count):
temp += audio[~i] - audio[count - 1 - i]
if temp < result:
result = temp
print(result)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers.
If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} K ⌉ bits to store each value. It then takes nk bits to store the whole file.
To reduce the memory consumption we need to apply some compression. One common way is to reduce the number of possible intensity values. We choose two integers l ≤ r, and after that all intensity values are changed in the following way: if the intensity value is within the range [l;r], we don't change it. If it is less than l, we change it to l; if it is greater than r, we change it to r. You can see that we lose some low and some high intensities.
Your task is to apply this compression in such a way that the file fits onto a disk of size I bytes, and the number of changed elements in the array is minimal possible.
We remind you that 1 byte contains 8 bits.
k = ⌈ log_{2} K ⌉ is the smallest integer such that K ≤ 2^{k}. In particular, if K = 1, then k = 0.
Input
The first line contains two integers n and I (1 ≤ n ≤ 4 ⋅ 10^{5}, 1 ≤ I ≤ 10^{8}) — the length of the array and the size of the disk in bytes, respectively.
The next line contains n integers a_{i} (0 ≤ a_{i} ≤ 10^{9}) — the array denoting the sound file.
Output
Print a single integer — the minimal possible number of changed elements.
Examples
Input
6 1
2 1 2 3 4 3
Output
2
Input
6 2
2 1 2 3 4 3
Output
0
Input
6 1
1 1 2 2 3 3
Output
2
Note
In the first example we can choose l=2, r=3. The array becomes 2 2 2 3 3 3, the number of distinct elements is K=2, and the sound file fits onto the disk. Only two values are changed.
In the second example the disk is larger, so the initial file fits it and no changes are required.
In the third example we have to change both 1s or both 3s.
|
n, m = map(int, input().split())
a = sorted(map(int, input().split()))
b = [0]
a += [1 << 30]
for i in range(n):
if a[i] < a[i + 1]:
b += [i + 1]
print(n - max((y - x for x, y in zip(b, b[1 << 8 * m // n :])), default=n))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER VAR LIST BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR LIST BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP BIN_OP NUMBER VAR VAR VAR
|
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers.
If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} K ⌉ bits to store each value. It then takes nk bits to store the whole file.
To reduce the memory consumption we need to apply some compression. One common way is to reduce the number of possible intensity values. We choose two integers l ≤ r, and after that all intensity values are changed in the following way: if the intensity value is within the range [l;r], we don't change it. If it is less than l, we change it to l; if it is greater than r, we change it to r. You can see that we lose some low and some high intensities.
Your task is to apply this compression in such a way that the file fits onto a disk of size I bytes, and the number of changed elements in the array is minimal possible.
We remind you that 1 byte contains 8 bits.
k = ⌈ log_{2} K ⌉ is the smallest integer such that K ≤ 2^{k}. In particular, if K = 1, then k = 0.
Input
The first line contains two integers n and I (1 ≤ n ≤ 4 ⋅ 10^{5}, 1 ≤ I ≤ 10^{8}) — the length of the array and the size of the disk in bytes, respectively.
The next line contains n integers a_{i} (0 ≤ a_{i} ≤ 10^{9}) — the array denoting the sound file.
Output
Print a single integer — the minimal possible number of changed elements.
Examples
Input
6 1
2 1 2 3 4 3
Output
2
Input
6 2
2 1 2 3 4 3
Output
0
Input
6 1
1 1 2 2 3 3
Output
2
Note
In the first example we can choose l=2, r=3. The array becomes 2 2 2 3 3 3, the number of distinct elements is K=2, and the sound file fits onto the disk. Only two values are changed.
In the second example the disk is larger, so the initial file fits it and no changes are required.
In the third example we have to change both 1s or both 3s.
|
n, I = list(map(int, input().strip().split()))
l = list(map(int, input().strip().split()))
l.sort()
k = 2 ** (I * 8 // n)
sol = []
i = 0
while i < n - 1:
count = 1
while i < n - 1 and l[i] == l[i + 1]:
count += 1
i += 1
sol.append(count)
i += 1
if len(l) > 1 and l[-1] != l[-2]:
sol.append(1)
s = 0
i = 0
while i < k and i < len(sol):
s += sol[i]
i += 1
ll = 0
temp = s
while i < len(sol):
temp += sol[i]
temp -= sol[ll]
if temp > s:
s = temp
i += 1
ll += 1
if n - s < 0 or n == 1:
print(0)
else:
print(n - s)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers.
If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} K ⌉ bits to store each value. It then takes nk bits to store the whole file.
To reduce the memory consumption we need to apply some compression. One common way is to reduce the number of possible intensity values. We choose two integers l ≤ r, and after that all intensity values are changed in the following way: if the intensity value is within the range [l;r], we don't change it. If it is less than l, we change it to l; if it is greater than r, we change it to r. You can see that we lose some low and some high intensities.
Your task is to apply this compression in such a way that the file fits onto a disk of size I bytes, and the number of changed elements in the array is minimal possible.
We remind you that 1 byte contains 8 bits.
k = ⌈ log_{2} K ⌉ is the smallest integer such that K ≤ 2^{k}. In particular, if K = 1, then k = 0.
Input
The first line contains two integers n and I (1 ≤ n ≤ 4 ⋅ 10^{5}, 1 ≤ I ≤ 10^{8}) — the length of the array and the size of the disk in bytes, respectively.
The next line contains n integers a_{i} (0 ≤ a_{i} ≤ 10^{9}) — the array denoting the sound file.
Output
Print a single integer — the minimal possible number of changed elements.
Examples
Input
6 1
2 1 2 3 4 3
Output
2
Input
6 2
2 1 2 3 4 3
Output
0
Input
6 1
1 1 2 2 3 3
Output
2
Note
In the first example we can choose l=2, r=3. The array becomes 2 2 2 3 3 3, the number of distinct elements is K=2, and the sound file fits onto the disk. Only two values are changed.
In the second example the disk is larger, so the initial file fits it and no changes are required.
In the third example we have to change both 1s or both 3s.
|
def mp():
return map(int, input().split())
n, I = mp()
a = sorted(list(mp()))
k = 2 ** (I * 8 // n)
cnt = [[a[0], 1]]
for i in range(1, n):
if cnt[-1][0] == a[i]:
cnt[-1][1] += 1
else:
cnt.append([a[i], 1])
N = n
n = len(cnt)
a = [i[1] for i in cnt]
s = sum(a[:k])
ans = s
for i in range(k, n):
s -= a[i - k]
s += a[i]
ans = max(ans, s)
print(sum(a) - ans)
|
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR LIST LIST VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER NUMBER VAR VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
|
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers.
If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} K ⌉ bits to store each value. It then takes nk bits to store the whole file.
To reduce the memory consumption we need to apply some compression. One common way is to reduce the number of possible intensity values. We choose two integers l ≤ r, and after that all intensity values are changed in the following way: if the intensity value is within the range [l;r], we don't change it. If it is less than l, we change it to l; if it is greater than r, we change it to r. You can see that we lose some low and some high intensities.
Your task is to apply this compression in such a way that the file fits onto a disk of size I bytes, and the number of changed elements in the array is minimal possible.
We remind you that 1 byte contains 8 bits.
k = ⌈ log_{2} K ⌉ is the smallest integer such that K ≤ 2^{k}. In particular, if K = 1, then k = 0.
Input
The first line contains two integers n and I (1 ≤ n ≤ 4 ⋅ 10^{5}, 1 ≤ I ≤ 10^{8}) — the length of the array and the size of the disk in bytes, respectively.
The next line contains n integers a_{i} (0 ≤ a_{i} ≤ 10^{9}) — the array denoting the sound file.
Output
Print a single integer — the minimal possible number of changed elements.
Examples
Input
6 1
2 1 2 3 4 3
Output
2
Input
6 2
2 1 2 3 4 3
Output
0
Input
6 1
1 1 2 2 3 3
Output
2
Note
In the first example we can choose l=2, r=3. The array becomes 2 2 2 3 3 3, the number of distinct elements is K=2, and the sound file fits onto the disk. Only two values are changed.
In the second example the disk is larger, so the initial file fits it and no changes are required.
In the third example we have to change both 1s or both 3s.
|
n, I = map(int, input().split())
a = list(map(int, input().split()))
I *= 8
k = I // n
if k >= 20:
res = 0
else:
K = 2**k
cc = {}
for ai in a:
cc[ai] = cc.get(ai, 0) + 1
pres = []
dd = sorted(cc)
for i in dd:
pres.append(cc[i])
for i in range(1, len(pres)):
pres[i] += pres[i - 1]
if K >= len(pres):
res = 0
else:
mm = 0
for i in range(K, len(pres)):
if mm < pres[i] - pres[i - K]:
mm = pres[i] - pres[i - K]
res = n - mm
print(res)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers.
If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} K ⌉ bits to store each value. It then takes nk bits to store the whole file.
To reduce the memory consumption we need to apply some compression. One common way is to reduce the number of possible intensity values. We choose two integers l ≤ r, and after that all intensity values are changed in the following way: if the intensity value is within the range [l;r], we don't change it. If it is less than l, we change it to l; if it is greater than r, we change it to r. You can see that we lose some low and some high intensities.
Your task is to apply this compression in such a way that the file fits onto a disk of size I bytes, and the number of changed elements in the array is minimal possible.
We remind you that 1 byte contains 8 bits.
k = ⌈ log_{2} K ⌉ is the smallest integer such that K ≤ 2^{k}. In particular, if K = 1, then k = 0.
Input
The first line contains two integers n and I (1 ≤ n ≤ 4 ⋅ 10^{5}, 1 ≤ I ≤ 10^{8}) — the length of the array and the size of the disk in bytes, respectively.
The next line contains n integers a_{i} (0 ≤ a_{i} ≤ 10^{9}) — the array denoting the sound file.
Output
Print a single integer — the minimal possible number of changed elements.
Examples
Input
6 1
2 1 2 3 4 3
Output
2
Input
6 2
2 1 2 3 4 3
Output
0
Input
6 1
1 1 2 2 3 3
Output
2
Note
In the first example we can choose l=2, r=3. The array becomes 2 2 2 3 3 3, the number of distinct elements is K=2, and the sound file fits onto the disk. Only two values are changed.
In the second example the disk is larger, so the initial file fits it and no changes are required.
In the third example we have to change both 1s or both 3s.
|
line = input()
tmp = line.split(" ")
n, k = int(tmp[0]), int(tmp[1])
line1 = input()
lst = [int(i) for i in line1.split(" ")]
lst.sort()
last, dis, ans, cnt = -1, 0, n, 0
left = 0
if k * 8 // n > n:
print("0")
else:
mx = 2 ** (k * 8 // n)
for idx, num in enumerate(lst):
cnt += 1
if num != last:
dis += 1
if dis > mx:
new_left = left
while lst[new_left] == lst[left]:
new_left += 1
cnt -= 1
left = new_left
dis -= 1
ans = min(ans, n - cnt)
last = num
print(ans)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers.
If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} K ⌉ bits to store each value. It then takes nk bits to store the whole file.
To reduce the memory consumption we need to apply some compression. One common way is to reduce the number of possible intensity values. We choose two integers l ≤ r, and after that all intensity values are changed in the following way: if the intensity value is within the range [l;r], we don't change it. If it is less than l, we change it to l; if it is greater than r, we change it to r. You can see that we lose some low and some high intensities.
Your task is to apply this compression in such a way that the file fits onto a disk of size I bytes, and the number of changed elements in the array is minimal possible.
We remind you that 1 byte contains 8 bits.
k = ⌈ log_{2} K ⌉ is the smallest integer such that K ≤ 2^{k}. In particular, if K = 1, then k = 0.
Input
The first line contains two integers n and I (1 ≤ n ≤ 4 ⋅ 10^{5}, 1 ≤ I ≤ 10^{8}) — the length of the array and the size of the disk in bytes, respectively.
The next line contains n integers a_{i} (0 ≤ a_{i} ≤ 10^{9}) — the array denoting the sound file.
Output
Print a single integer — the minimal possible number of changed elements.
Examples
Input
6 1
2 1 2 3 4 3
Output
2
Input
6 2
2 1 2 3 4 3
Output
0
Input
6 1
1 1 2 2 3 3
Output
2
Note
In the first example we can choose l=2, r=3. The array becomes 2 2 2 3 3 3, the number of distinct elements is K=2, and the sound file fits onto the disk. Only two values are changed.
In the second example the disk is larger, so the initial file fits it and no changes are required.
In the third example we have to change both 1s or both 3s.
|
import sys
input = sys.stdin.readline
n, I = map(int, input().split())
a = list(map(int, input().split()))
k = I * 8 // n
K = 2**k
d = {}
for i in range(n):
if a[i] not in d:
d[a[i]] = 0
d[a[i]] += 1
keys = list(d.keys())
keys.sort()
num = 0
maxNum = 0
for i in range(len(keys)):
num += d[keys[i]]
if i >= K:
num -= d[keys[i - K]]
maxNum = max(maxNum, num)
res = n - maxNum
print(res)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers.
If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} K ⌉ bits to store each value. It then takes nk bits to store the whole file.
To reduce the memory consumption we need to apply some compression. One common way is to reduce the number of possible intensity values. We choose two integers l ≤ r, and after that all intensity values are changed in the following way: if the intensity value is within the range [l;r], we don't change it. If it is less than l, we change it to l; if it is greater than r, we change it to r. You can see that we lose some low and some high intensities.
Your task is to apply this compression in such a way that the file fits onto a disk of size I bytes, and the number of changed elements in the array is minimal possible.
We remind you that 1 byte contains 8 bits.
k = ⌈ log_{2} K ⌉ is the smallest integer such that K ≤ 2^{k}. In particular, if K = 1, then k = 0.
Input
The first line contains two integers n and I (1 ≤ n ≤ 4 ⋅ 10^{5}, 1 ≤ I ≤ 10^{8}) — the length of the array and the size of the disk in bytes, respectively.
The next line contains n integers a_{i} (0 ≤ a_{i} ≤ 10^{9}) — the array denoting the sound file.
Output
Print a single integer — the minimal possible number of changed elements.
Examples
Input
6 1
2 1 2 3 4 3
Output
2
Input
6 2
2 1 2 3 4 3
Output
0
Input
6 1
1 1 2 2 3 3
Output
2
Note
In the first example we can choose l=2, r=3. The array becomes 2 2 2 3 3 3, the number of distinct elements is K=2, and the sound file fits onto the disk. Only two values are changed.
In the second example the disk is larger, so the initial file fits it and no changes are required.
In the third example we have to change both 1s or both 3s.
|
n, I = map(int, input().split())
a = list(map(int, input().split()))
k = 2 ** (I * 8 // n)
a.sort()
ls = []
cnt = 1
for i in range(1, n):
if a[i] == a[i - 1]:
cnt += 1
else:
ls.append([cnt, a[i - 1]])
cnt = 1
if cnt:
ls.append([cnt, a[-1]])
dis = len(ls)
if dis <= k:
print(0)
else:
prefix = [(0) for i in range(len(ls) + 1)]
for i in range(1, len(ls) + 1):
prefix[i] = prefix[i - 1] + ls[i - 1][0]
suffix = [(0) for i in range(len(ls) + 1)]
for i in range(len(ls) - 1, -1, -1):
suffix[i] = suffix[i + 1] + ls[i][0]
ans = n
for i in range(dis - k + 1):
ans = min(ans, prefix[i] + suffix[len(ls) - dis + k + i])
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR LIST VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers.
If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} K ⌉ bits to store each value. It then takes nk bits to store the whole file.
To reduce the memory consumption we need to apply some compression. One common way is to reduce the number of possible intensity values. We choose two integers l ≤ r, and after that all intensity values are changed in the following way: if the intensity value is within the range [l;r], we don't change it. If it is less than l, we change it to l; if it is greater than r, we change it to r. You can see that we lose some low and some high intensities.
Your task is to apply this compression in such a way that the file fits onto a disk of size I bytes, and the number of changed elements in the array is minimal possible.
We remind you that 1 byte contains 8 bits.
k = ⌈ log_{2} K ⌉ is the smallest integer such that K ≤ 2^{k}. In particular, if K = 1, then k = 0.
Input
The first line contains two integers n and I (1 ≤ n ≤ 4 ⋅ 10^{5}, 1 ≤ I ≤ 10^{8}) — the length of the array and the size of the disk in bytes, respectively.
The next line contains n integers a_{i} (0 ≤ a_{i} ≤ 10^{9}) — the array denoting the sound file.
Output
Print a single integer — the minimal possible number of changed elements.
Examples
Input
6 1
2 1 2 3 4 3
Output
2
Input
6 2
2 1 2 3 4 3
Output
0
Input
6 1
1 1 2 2 3 3
Output
2
Note
In the first example we can choose l=2, r=3. The array becomes 2 2 2 3 3 3, the number of distinct elements is K=2, and the sound file fits onto the disk. Only two values are changed.
In the second example the disk is larger, so the initial file fits it and no changes are required.
In the third example we have to change both 1s or both 3s.
|
from itertools import groupby
def solve():
n, disk = list(map(int, input().split()))
a = list(map(int, input().split()))
k = int(disk * 8 / n)
dist = 1 << k
counts = [len(list(group)) for key, group in groupby(sorted(a))]
cur_changes = sum(counts[dist:])
ans = cur_changes
for i in range(0, len(counts) - dist):
cur_changes += counts[i]
cur_changes -= counts[i + dist]
ans = min(ans, cur_changes)
print(ans)
solve()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers.
If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} K ⌉ bits to store each value. It then takes nk bits to store the whole file.
To reduce the memory consumption we need to apply some compression. One common way is to reduce the number of possible intensity values. We choose two integers l ≤ r, and after that all intensity values are changed in the following way: if the intensity value is within the range [l;r], we don't change it. If it is less than l, we change it to l; if it is greater than r, we change it to r. You can see that we lose some low and some high intensities.
Your task is to apply this compression in such a way that the file fits onto a disk of size I bytes, and the number of changed elements in the array is minimal possible.
We remind you that 1 byte contains 8 bits.
k = ⌈ log_{2} K ⌉ is the smallest integer such that K ≤ 2^{k}. In particular, if K = 1, then k = 0.
Input
The first line contains two integers n and I (1 ≤ n ≤ 4 ⋅ 10^{5}, 1 ≤ I ≤ 10^{8}) — the length of the array and the size of the disk in bytes, respectively.
The next line contains n integers a_{i} (0 ≤ a_{i} ≤ 10^{9}) — the array denoting the sound file.
Output
Print a single integer — the minimal possible number of changed elements.
Examples
Input
6 1
2 1 2 3 4 3
Output
2
Input
6 2
2 1 2 3 4 3
Output
0
Input
6 1
1 1 2 2 3 3
Output
2
Note
In the first example we can choose l=2, r=3. The array becomes 2 2 2 3 3 3, the number of distinct elements is K=2, and the sound file fits onto the disk. Only two values are changed.
In the second example the disk is larger, so the initial file fits it and no changes are required.
In the third example we have to change both 1s or both 3s.
|
ni = input()
n, i = list(map(int, ni.split()))
nums = input()
nums = list(map(int, nums.split()))
i = i * 8
mm = {}
for k in nums:
if k in mm:
mm[k] += 1
else:
mm[k] = 1
keys = mm.keys()
s_keys = sorted(list(keys))
bits = i // n
nums_len = pow(2, bits)
right = nums_len
left = 0
if right >= len(s_keys):
print(0)
else:
min_change = 999999
now_change = 0
for k in s_keys[right:]:
now_change += mm[k]
while right < len(s_keys):
if now_change < min_change:
min_change = now_change
now_change += mm[s_keys[left]]
now_change -= mm[s_keys[right]]
left += 1
right += 1
print(min_change)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR VAR WHILE VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers.
If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} K ⌉ bits to store each value. It then takes nk bits to store the whole file.
To reduce the memory consumption we need to apply some compression. One common way is to reduce the number of possible intensity values. We choose two integers l ≤ r, and after that all intensity values are changed in the following way: if the intensity value is within the range [l;r], we don't change it. If it is less than l, we change it to l; if it is greater than r, we change it to r. You can see that we lose some low and some high intensities.
Your task is to apply this compression in such a way that the file fits onto a disk of size I bytes, and the number of changed elements in the array is minimal possible.
We remind you that 1 byte contains 8 bits.
k = ⌈ log_{2} K ⌉ is the smallest integer such that K ≤ 2^{k}. In particular, if K = 1, then k = 0.
Input
The first line contains two integers n and I (1 ≤ n ≤ 4 ⋅ 10^{5}, 1 ≤ I ≤ 10^{8}) — the length of the array and the size of the disk in bytes, respectively.
The next line contains n integers a_{i} (0 ≤ a_{i} ≤ 10^{9}) — the array denoting the sound file.
Output
Print a single integer — the minimal possible number of changed elements.
Examples
Input
6 1
2 1 2 3 4 3
Output
2
Input
6 2
2 1 2 3 4 3
Output
0
Input
6 1
1 1 2 2 3 3
Output
2
Note
In the first example we can choose l=2, r=3. The array becomes 2 2 2 3 3 3, the number of distinct elements is K=2, and the sound file fits onto the disk. Only two values are changed.
In the second example the disk is larger, so the initial file fits it and no changes are required.
In the third example we have to change both 1s or both 3s.
|
n, i = map(int, input().split())
lst = list(map(int, input().split()))
i *= 8
k = i // n
imax = 2**k
idict = {}
for i in lst:
if idict.get(i) == None:
idict[i] = 1
else:
idict[i] += 1
lst = sorted(idict.keys())
isum = 0
imin = None
l = 0
q = 0
r = 0
while r < len(lst):
isum += 1
q += idict[lst[r]]
r += 1
if isum > imax or r == len(lst):
copyisum = q - idict[lst[r - 1]]
if r == len(lst) and isum <= imax:
copyisum += idict[lst[r - 1]]
shakal = n - copyisum
if imin == None or imin > shakal:
imin = shakal
while isum > imax:
isum -= 1
q -= idict[lst[l]]
l += 1
print(imin)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR DICT FOR VAR VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NONE ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NONE VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers.
If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} K ⌉ bits to store each value. It then takes nk bits to store the whole file.
To reduce the memory consumption we need to apply some compression. One common way is to reduce the number of possible intensity values. We choose two integers l ≤ r, and after that all intensity values are changed in the following way: if the intensity value is within the range [l;r], we don't change it. If it is less than l, we change it to l; if it is greater than r, we change it to r. You can see that we lose some low and some high intensities.
Your task is to apply this compression in such a way that the file fits onto a disk of size I bytes, and the number of changed elements in the array is minimal possible.
We remind you that 1 byte contains 8 bits.
k = ⌈ log_{2} K ⌉ is the smallest integer such that K ≤ 2^{k}. In particular, if K = 1, then k = 0.
Input
The first line contains two integers n and I (1 ≤ n ≤ 4 ⋅ 10^{5}, 1 ≤ I ≤ 10^{8}) — the length of the array and the size of the disk in bytes, respectively.
The next line contains n integers a_{i} (0 ≤ a_{i} ≤ 10^{9}) — the array denoting the sound file.
Output
Print a single integer — the minimal possible number of changed elements.
Examples
Input
6 1
2 1 2 3 4 3
Output
2
Input
6 2
2 1 2 3 4 3
Output
0
Input
6 1
1 1 2 2 3 3
Output
2
Note
In the first example we can choose l=2, r=3. The array becomes 2 2 2 3 3 3, the number of distinct elements is K=2, and the sound file fits onto the disk. Only two values are changed.
In the second example the disk is larger, so the initial file fits it and no changes are required.
In the third example we have to change both 1s or both 3s.
|
from sys import stdin
n, i = map(int, stdin.readline().split())
a = list(map(int, stdin.readline().split()))
i *= 8
K = 2 ** (i // n)
a.sort()
b = []
for i in a:
if not b or b[-1][0] != i:
b.append([i, 0])
b[-1][1] += 1
current = 0
for i in range(K, len(b)):
current += b[i][1]
ans = current
for r in range(K, len(b)):
current += b[r - K][1]
current -= b[r][1]
ans = min(ans, current)
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR LIST VAR NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers.
If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} K ⌉ bits to store each value. It then takes nk bits to store the whole file.
To reduce the memory consumption we need to apply some compression. One common way is to reduce the number of possible intensity values. We choose two integers l ≤ r, and after that all intensity values are changed in the following way: if the intensity value is within the range [l;r], we don't change it. If it is less than l, we change it to l; if it is greater than r, we change it to r. You can see that we lose some low and some high intensities.
Your task is to apply this compression in such a way that the file fits onto a disk of size I bytes, and the number of changed elements in the array is minimal possible.
We remind you that 1 byte contains 8 bits.
k = ⌈ log_{2} K ⌉ is the smallest integer such that K ≤ 2^{k}. In particular, if K = 1, then k = 0.
Input
The first line contains two integers n and I (1 ≤ n ≤ 4 ⋅ 10^{5}, 1 ≤ I ≤ 10^{8}) — the length of the array and the size of the disk in bytes, respectively.
The next line contains n integers a_{i} (0 ≤ a_{i} ≤ 10^{9}) — the array denoting the sound file.
Output
Print a single integer — the minimal possible number of changed elements.
Examples
Input
6 1
2 1 2 3 4 3
Output
2
Input
6 2
2 1 2 3 4 3
Output
0
Input
6 1
1 1 2 2 3 3
Output
2
Note
In the first example we can choose l=2, r=3. The array becomes 2 2 2 3 3 3, the number of distinct elements is K=2, and the sound file fits onto the disk. Only two values are changed.
In the second example the disk is larger, so the initial file fits it and no changes are required.
In the third example we have to change both 1s or both 3s.
|
n, I = map(int, input().split())
a = sorted(list(map(int, input().split())))
cur = 0
b = [0]
for i in range(1, n):
if a[i] != a[i - 1]:
cur += 1
b.append(cur)
r = 1
ans = int(1e18)
for l in range(len(b)):
ma = b[l] + 2 ** min(I * 8 // n, 30) - 1
while r < n and b[r] <= ma:
r += 1
ans = min(ans, l + (n - r))
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers.
If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} K ⌉ bits to store each value. It then takes nk bits to store the whole file.
To reduce the memory consumption we need to apply some compression. One common way is to reduce the number of possible intensity values. We choose two integers l ≤ r, and after that all intensity values are changed in the following way: if the intensity value is within the range [l;r], we don't change it. If it is less than l, we change it to l; if it is greater than r, we change it to r. You can see that we lose some low and some high intensities.
Your task is to apply this compression in such a way that the file fits onto a disk of size I bytes, and the number of changed elements in the array is minimal possible.
We remind you that 1 byte contains 8 bits.
k = ⌈ log_{2} K ⌉ is the smallest integer such that K ≤ 2^{k}. In particular, if K = 1, then k = 0.
Input
The first line contains two integers n and I (1 ≤ n ≤ 4 ⋅ 10^{5}, 1 ≤ I ≤ 10^{8}) — the length of the array and the size of the disk in bytes, respectively.
The next line contains n integers a_{i} (0 ≤ a_{i} ≤ 10^{9}) — the array denoting the sound file.
Output
Print a single integer — the minimal possible number of changed elements.
Examples
Input
6 1
2 1 2 3 4 3
Output
2
Input
6 2
2 1 2 3 4 3
Output
0
Input
6 1
1 1 2 2 3 3
Output
2
Note
In the first example we can choose l=2, r=3. The array becomes 2 2 2 3 3 3, the number of distinct elements is K=2, and the sound file fits onto the disk. Only two values are changed.
In the second example the disk is larger, so the initial file fits it and no changes are required.
In the third example we have to change both 1s or both 3s.
|
from sys import stdin, stdout
N, I = [int(x) for x in stdin.readline().split()]
arr = [int(x) for x in stdin.readline().split()]
arr.sort()
bits = I * 8
bound = bits // N
if bound >= 50:
bound = 50
max_K = 2**bound
freq = []
f = 0
last = arr[0]
for num in arr:
if num == last:
f += 1
else:
freq.append(f)
f = 1
last = num
freq.append(f)
prefix = [0] * len(freq)
s = 0
i = 0
for f in freq:
s += f
prefix[i] = s
i += 1
res = N + 1
for i in range(max_K - 1, len(freq)):
if i == max_K - 1:
res = min(res, N - prefix[i])
else:
res = min(res, N - prefix[i] + prefix[i - max_K])
if res == N + 1:
print(0)
else:
print(res)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers.
If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} K ⌉ bits to store each value. It then takes nk bits to store the whole file.
To reduce the memory consumption we need to apply some compression. One common way is to reduce the number of possible intensity values. We choose two integers l ≤ r, and after that all intensity values are changed in the following way: if the intensity value is within the range [l;r], we don't change it. If it is less than l, we change it to l; if it is greater than r, we change it to r. You can see that we lose some low and some high intensities.
Your task is to apply this compression in such a way that the file fits onto a disk of size I bytes, and the number of changed elements in the array is minimal possible.
We remind you that 1 byte contains 8 bits.
k = ⌈ log_{2} K ⌉ is the smallest integer such that K ≤ 2^{k}. In particular, if K = 1, then k = 0.
Input
The first line contains two integers n and I (1 ≤ n ≤ 4 ⋅ 10^{5}, 1 ≤ I ≤ 10^{8}) — the length of the array and the size of the disk in bytes, respectively.
The next line contains n integers a_{i} (0 ≤ a_{i} ≤ 10^{9}) — the array denoting the sound file.
Output
Print a single integer — the minimal possible number of changed elements.
Examples
Input
6 1
2 1 2 3 4 3
Output
2
Input
6 2
2 1 2 3 4 3
Output
0
Input
6 1
1 1 2 2 3 3
Output
2
Note
In the first example we can choose l=2, r=3. The array becomes 2 2 2 3 3 3, the number of distinct elements is K=2, and the sound file fits onto the disk. Only two values are changed.
In the second example the disk is larger, so the initial file fits it and no changes are required.
In the third example we have to change both 1s or both 3s.
|
n, I = [int(i) for i in input().split()]
l1 = [int(i) for i in input().split()]
k = 8 * I // n
K = 2**k
l1.sort()
dstnct = []
dstnct.append(0)
for i in range(1, len(l1)):
if l1[i] != l1[i - 1]:
dstnct.append(i)
if len(dstnct) <= K:
print(0)
else:
print(n - max(dstnct[i + K] - dstnct[i] for i in range(len(dstnct) - K)))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
|
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers.
If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} K ⌉ bits to store each value. It then takes nk bits to store the whole file.
To reduce the memory consumption we need to apply some compression. One common way is to reduce the number of possible intensity values. We choose two integers l ≤ r, and after that all intensity values are changed in the following way: if the intensity value is within the range [l;r], we don't change it. If it is less than l, we change it to l; if it is greater than r, we change it to r. You can see that we lose some low and some high intensities.
Your task is to apply this compression in such a way that the file fits onto a disk of size I bytes, and the number of changed elements in the array is minimal possible.
We remind you that 1 byte contains 8 bits.
k = ⌈ log_{2} K ⌉ is the smallest integer such that K ≤ 2^{k}. In particular, if K = 1, then k = 0.
Input
The first line contains two integers n and I (1 ≤ n ≤ 4 ⋅ 10^{5}, 1 ≤ I ≤ 10^{8}) — the length of the array and the size of the disk in bytes, respectively.
The next line contains n integers a_{i} (0 ≤ a_{i} ≤ 10^{9}) — the array denoting the sound file.
Output
Print a single integer — the minimal possible number of changed elements.
Examples
Input
6 1
2 1 2 3 4 3
Output
2
Input
6 2
2 1 2 3 4 3
Output
0
Input
6 1
1 1 2 2 3 3
Output
2
Note
In the first example we can choose l=2, r=3. The array becomes 2 2 2 3 3 3, the number of distinct elements is K=2, and the sound file fits onto the disk. Only two values are changed.
In the second example the disk is larger, so the initial file fits it and no changes are required.
In the third example we have to change both 1s or both 3s.
|
from itertools import accumulate
n, l = map(int, input().split())
a = [*map(int, input().split())]
a.sort()
p = 8 * l // n
if p >= 20:
print(0)
exit()
x = 1 << p
v = []
prev = -1
for i in a:
if i != prev:
v.append(1)
else:
v[-1] += 1
prev = i
s = [0] + [*accumulate(v[::-1])]
ans = 1000000000.0
temp = 0
for i in range(len(v)):
ans = min(ans, temp + s[max(len(v) - i - x, 0)])
temp += v[i]
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER LIST FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers.
If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} K ⌉ bits to store each value. It then takes nk bits to store the whole file.
To reduce the memory consumption we need to apply some compression. One common way is to reduce the number of possible intensity values. We choose two integers l ≤ r, and after that all intensity values are changed in the following way: if the intensity value is within the range [l;r], we don't change it. If it is less than l, we change it to l; if it is greater than r, we change it to r. You can see that we lose some low and some high intensities.
Your task is to apply this compression in such a way that the file fits onto a disk of size I bytes, and the number of changed elements in the array is minimal possible.
We remind you that 1 byte contains 8 bits.
k = ⌈ log_{2} K ⌉ is the smallest integer such that K ≤ 2^{k}. In particular, if K = 1, then k = 0.
Input
The first line contains two integers n and I (1 ≤ n ≤ 4 ⋅ 10^{5}, 1 ≤ I ≤ 10^{8}) — the length of the array and the size of the disk in bytes, respectively.
The next line contains n integers a_{i} (0 ≤ a_{i} ≤ 10^{9}) — the array denoting the sound file.
Output
Print a single integer — the minimal possible number of changed elements.
Examples
Input
6 1
2 1 2 3 4 3
Output
2
Input
6 2
2 1 2 3 4 3
Output
0
Input
6 1
1 1 2 2 3 3
Output
2
Note
In the first example we can choose l=2, r=3. The array becomes 2 2 2 3 3 3, the number of distinct elements is K=2, and the sound file fits onto the disk. Only two values are changed.
In the second example the disk is larger, so the initial file fits it and no changes are required.
In the third example we have to change both 1s or both 3s.
|
n, I = map(int, input().split())
I *= 8
array = list(map(int, input().split()))
def log(x):
l = 0
while 2**l < x:
l += 1
return l
array.sort()
izn = []
d = {}
for el in array:
if el in d:
d[el] += 1
else:
d[el] = 1
izn.append(el)
f = len(izn)
j = 0
pos = 0
count = 0
un = 0
for i in range(f):
while j < f and log(un + 1) * n <= I:
count += d[izn[j]]
if pos < count:
pos = count
j += 1
un += 1
un -= 1
count -= d[izn[i]]
print(n - pos)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP NUMBER VAR VAR VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers.
If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} K ⌉ bits to store each value. It then takes nk bits to store the whole file.
To reduce the memory consumption we need to apply some compression. One common way is to reduce the number of possible intensity values. We choose two integers l ≤ r, and after that all intensity values are changed in the following way: if the intensity value is within the range [l;r], we don't change it. If it is less than l, we change it to l; if it is greater than r, we change it to r. You can see that we lose some low and some high intensities.
Your task is to apply this compression in such a way that the file fits onto a disk of size I bytes, and the number of changed elements in the array is minimal possible.
We remind you that 1 byte contains 8 bits.
k = ⌈ log_{2} K ⌉ is the smallest integer such that K ≤ 2^{k}. In particular, if K = 1, then k = 0.
Input
The first line contains two integers n and I (1 ≤ n ≤ 4 ⋅ 10^{5}, 1 ≤ I ≤ 10^{8}) — the length of the array and the size of the disk in bytes, respectively.
The next line contains n integers a_{i} (0 ≤ a_{i} ≤ 10^{9}) — the array denoting the sound file.
Output
Print a single integer — the minimal possible number of changed elements.
Examples
Input
6 1
2 1 2 3 4 3
Output
2
Input
6 2
2 1 2 3 4 3
Output
0
Input
6 1
1 1 2 2 3 3
Output
2
Note
In the first example we can choose l=2, r=3. The array becomes 2 2 2 3 3 3, the number of distinct elements is K=2, and the sound file fits onto the disk. Only two values are changed.
In the second example the disk is larger, so the initial file fits it and no changes are required.
In the third example we have to change both 1s or both 3s.
|
import sys
n, I = [int(i) for i in input().split()]
num = 1 << 8 * I // n
data = [int(i) for i in input().split()]
dic = {}
for d in data:
if d in dic:
dic[d] += 1
else:
dic[d] = 1
if 8 * I < n:
print(n - max(dic.values()))
sys.exit()
vals = list(dic.keys())
vals.sort()
am = len(vals)
if am <= num:
print(0)
sys.exit()
sumto = [dic[vals[0]]]
for i in range(1, am):
sumto.append(sumto[-1] + dic[vals[i]])
kept = sumto[num - 1]
for i in range(am - num):
kept2 = sumto[i + num] - sumto[i]
if kept2 > kept:
kept = kept2
print(n - kept)
|
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers.
If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} K ⌉ bits to store each value. It then takes nk bits to store the whole file.
To reduce the memory consumption we need to apply some compression. One common way is to reduce the number of possible intensity values. We choose two integers l ≤ r, and after that all intensity values are changed in the following way: if the intensity value is within the range [l;r], we don't change it. If it is less than l, we change it to l; if it is greater than r, we change it to r. You can see that we lose some low and some high intensities.
Your task is to apply this compression in such a way that the file fits onto a disk of size I bytes, and the number of changed elements in the array is minimal possible.
We remind you that 1 byte contains 8 bits.
k = ⌈ log_{2} K ⌉ is the smallest integer such that K ≤ 2^{k}. In particular, if K = 1, then k = 0.
Input
The first line contains two integers n and I (1 ≤ n ≤ 4 ⋅ 10^{5}, 1 ≤ I ≤ 10^{8}) — the length of the array and the size of the disk in bytes, respectively.
The next line contains n integers a_{i} (0 ≤ a_{i} ≤ 10^{9}) — the array denoting the sound file.
Output
Print a single integer — the minimal possible number of changed elements.
Examples
Input
6 1
2 1 2 3 4 3
Output
2
Input
6 2
2 1 2 3 4 3
Output
0
Input
6 1
1 1 2 2 3 3
Output
2
Note
In the first example we can choose l=2, r=3. The array becomes 2 2 2 3 3 3, the number of distinct elements is K=2, and the sound file fits onto the disk. Only two values are changed.
In the second example the disk is larger, so the initial file fits it and no changes are required.
In the third example we have to change both 1s or both 3s.
|
def main():
n, k = map(int, input().split())
k *= 8
a = sorted(list(map(int, input().split())))
a1 = [a[0]]
for i in range(1, n):
if a[i] != a[i - 1]:
a1.append(a[i])
count = k // n
ans = pow(2, count)
b = {}
for i in range(len(a1)):
b[a1[i]] = i
c = [(0) for i in range(n)]
for i in range(n):
c[b[a[i]]] += 1
pr = [0]
for i in range(len(a1)):
pr.append(c[i] + pr[-1])
min1 = 10**9
for i in range(len(a1)):
min1 = min(n - (pr[min(i + ans, len(a1))] - pr[i]), min1)
print(min1)
main()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers.
If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} K ⌉ bits to store each value. It then takes nk bits to store the whole file.
To reduce the memory consumption we need to apply some compression. One common way is to reduce the number of possible intensity values. We choose two integers l ≤ r, and after that all intensity values are changed in the following way: if the intensity value is within the range [l;r], we don't change it. If it is less than l, we change it to l; if it is greater than r, we change it to r. You can see that we lose some low and some high intensities.
Your task is to apply this compression in such a way that the file fits onto a disk of size I bytes, and the number of changed elements in the array is minimal possible.
We remind you that 1 byte contains 8 bits.
k = ⌈ log_{2} K ⌉ is the smallest integer such that K ≤ 2^{k}. In particular, if K = 1, then k = 0.
Input
The first line contains two integers n and I (1 ≤ n ≤ 4 ⋅ 10^{5}, 1 ≤ I ≤ 10^{8}) — the length of the array and the size of the disk in bytes, respectively.
The next line contains n integers a_{i} (0 ≤ a_{i} ≤ 10^{9}) — the array denoting the sound file.
Output
Print a single integer — the minimal possible number of changed elements.
Examples
Input
6 1
2 1 2 3 4 3
Output
2
Input
6 2
2 1 2 3 4 3
Output
0
Input
6 1
1 1 2 2 3 3
Output
2
Note
In the first example we can choose l=2, r=3. The array becomes 2 2 2 3 3 3, the number of distinct elements is K=2, and the sound file fits onto the disk. Only two values are changed.
In the second example the disk is larger, so the initial file fits it and no changes are required.
In the third example we have to change both 1s or both 3s.
|
import sys
from itertools import accumulate
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
N, K = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)
L = []
prev = -1
for a in A:
if a == prev:
L[-1] += 1
else:
L.append(1)
prev = a
max_types = int(2 ** (8 * K // N))
all_types = len(L)
del_types = all_types - max_types
if del_types <= 0:
ans = 0
else:
ans = float("inf")
sum_L = N
L_acc = [0] + list(accumulate(L))
for i in range(len(L) - max_types):
s = L_acc[i + max_types] - L_acc[i]
ans = min(ans, sum_L - s)
print(ans)
|
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.