KEMBAR78
Problem - A - Codeforces | PDF | Computer Programming | Algorithms
0% found this document useful (0 votes)
90 views2 pages

Problem - A - Codeforces

The document describes a problem from Codeforces Round 1042 (Div. 3) involving two arrays, a and b, where a process called 'The Lever' iterates based on specific conditions. The goal is to determine the number of iterations The Lever performs, which is consistent across random index selections. The input consists of multiple test cases, each specifying the lengths and values of the arrays, and the output is the number of iterations for each test case.

Uploaded by

molla22205101933
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views2 pages

Problem - A - Codeforces

The document describes a problem from Codeforces Round 1042 (Div. 3) involving two arrays, a and b, where a process called 'The Lever' iterates based on specific conditions. The goal is to determine the number of iterations The Lever performs, which is consistent across random index selections. The input consists of multiple test cases, each specifying the lengths and values of the arrays, and the output is the number of iterations for each test case.

Uploaded by

molla22205101933
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

8/10/25, 8:50 PM Problem - A - Codeforces

 |
sawon_777 | Logout

HOME TOP CATALOG CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP

PROBLEMS SUBMIT CODE MY SUBMISSIONS STATUS STANDINGS CUSTOM INVOCATION

Codeforces Round 1042 (Div. 3)


A. Lever Contest is running
time limit per test: 2 seconds
01:59:46
memory limit per test: 256 megabytes
Contestant
In Divergent Universe, The Lever iterates itself given two arrays a and b of length n. In each
iteration, The Lever will do the following:

1. Choose a random index i such that ai > bi . Then, decrease ai by 1. If there does not exist
such i , ignore this step. → Submit?
2. Choose a random index i such that ai < bi . Then, increase ai by 1. If there does not exist
such i , ignore this step. Language: GNU G++23 14.2 (64 bit, ms

Choose
After each iteration, the Lever will check if step 1 is ignored, and if so, it will end its iteration. Choose File No file chosen
file:

You're given the two arrays. Find the number of iterations that the Lever does. It can be shown Submit
this number is fixed over all possibilities of random indices that The Lever can choose for each
step.

Input
Each test contains multiple test cases. The first line contains the number of test cases t (
4
1 ≤ t ≤ 10 ). The description of the test cases follows.

The first line of each test case contains one integer n (1 ≤ n ≤ 10 ).

The second line of each test case contains n integers a1 , a2 , … , an (1 ≤ ai ≤ 10 ).

The third line of each test case contains n integers b1 , b2 , … , bn (1 ≤ bi ≤ 10 ).

Output
For each test case, output one integer — the number of iterations that the Lever does.
1
Example
input Copy

4
2
7 3
5 6
3
3 1 4
3 1 4
1
10
1
6
1 1 4 5 1 4
1 9 1 9 8 1

output Copy

3
1
10
7

Note
In the first sample case:

In the first iteration, the Lever decreases a1 by 1 and increases a2 by 1, and a becomes [6, 4].

https://codeforces.com/contest/2131/problem/A 1/2
8/10/25, 8:50 PM Problem - A - Codeforces

 In the second iteration, the Lever decreases a 1


by 1 and increases a2 by 1, and a becomes
[5, 5] .

In the third iteration, the Lever increases a2 by 1, and a becomes [5, 6]. Since it fails to decrease
an element, its iteration ends. Therefore, the answer is 3.

In the second sample case, the Lever does nothing in its first iteration, and thus it does only one
iteration.

Codeforces (c) Copyright 2010-2025 Mike Mirzayanov


The only programming contests Web 2.0 platform
Server time: Aug/10/2025 20:49:28UTC+6 (k2).
Desktop version, switch to mobile version.
Privacy Policy | Terms and Conditions

Supported by

https://codeforces.com/contest/2131/problem/A 2/2

You might also like