week 06
week 06
Flag question
Input Format
Output format
Example
Input:
REC-CIS
1
3135
Output:
Input:
3135
99
Output:
1 1 1
3 1 3 5
4
1 0 0
3 1 3 5
99
Sam loves chocolates and starts buying them on the 1st day of the year. Each day of
the year, x, is numbered from 1 to Y. On days when x is odd, Sam will buy x chocolates;
on days when x is even, Sam will not purchase any chocolates.
Question 2
Complete the code in the editor so that for each day Ni (where 1 ≤ x ≤ N ≤ Y) in array
REC-CIS
arr, the number of chocolates Sam purchased (during days 1 through N) is printed on a
Correct
new line. This is a function-only challenge, so input is handled for you by the locked
Marked out of
stub code in the editor.
5.00
Flag question
Input Format
The locked code in the editor handles reading the following input from stdin,
assembling it into an array of integers (arr), and calling calculate(arr).
The first line of input contains an integer, T (the number of test cases). Each line i of the
T subsequent lines describes the ith test case as an integer, Ni (the number of days).
Constraints
1 ≤ T ≤ 2 × 105
1 ≤ N ≤ 2 × 106
1≤x≤N≤Y
Output Format
For each test case, Ti in arr, your calculate method should print the total number of
chocolates Sam purchased by day Ni on a new line.
Sample Input 0
3
REC-CIS
1
Sample Output 0
Explanation
Test Case 0: N = 1
Test Case 1: N = 2
Sam buys 1 chocolate on day 1 and 0 on day 2. This gives us a total of 1 chocolate.
Thus, we print 1 on a new line.
Test Case 2: N = 3
Sam buys 1 chocolate on day 1, 0 on day 2, and 3 on day 3. This gives us a total of 4
chocolates. Thus, we print 4 on a new line.
3 1 1
1 1 1
2 4 4
3
10 1296 1296
REC-CIS
71 2500 2500
100 1849 1849
86 729 729
54 400 400
40 25 25
9 1521 1521
77 25 25
9 49 49
13 2401 2401
98
Question 3 The number of goals achieved by two football teams in matches in a league is given in
Correct the form of two lists. Consider:
Marked out of
7.00
Flag question
• Football team A, has played three matches, and has scored { 1 , 2 , 3 } goals in
each match respectively.
• Football team B, has played two matches, and has scored { 2, 4 } goals in each
match respectively.
• Your task is to compute, for each match of team B, the total number of matches of
team A, where team A has scored less than or equal to the number of goals scored by
team B in that match.
• For 2 goals scored by team B in its first match, team A has 2 matches with scores 1
and 2.
• For 4 goals scored by team B in its second match, team A has 3 matches with
scores 1, 2 and 3.
Constraints
• 2 ≤ n, m ≤ 105
Input from stdin will be processed as follows and passed to the function.
The next n lines each contain an integer describing nums[j] where 0 ≤ j < n.
The next line contains an integer m, the number of elements in maxes.
The next m lines each contain an integer describing maxes[i] where 0 ≤ i < m.
Sample Case 0
Sample Input 0
REC-CIS
4
2
Sample Output 0
Explanation 0
Sample Case 1
REC-CIS
Sample Input 1
10
5
4
Sample Output 1
3
4
Explanation 1
We are given, n = 5, nums = [2, 10, 5, 4, 8], m = 4, and maxes = [3, 1, 7, 8].
5 1 1
2 0 0
10 3 3
5 4 4
4
8
4
3
1
7
8
Finish review