Starting from:
$20

$14

Week 2 Programming Assignment Solution


Select your language (C/C++/Java/Python2/Python3)

Paste your code into the submission window.

There are some public test cases and some (hidden) private test cases. "Compile and run" will evaluate your submission against the public test cases

"Submit" will evaluate your submission against the hidden private test cases and report a score on 100. There are 10 private testcases in all, each with equal weightage. You will only get a score on 100. You will not get feedback on which private testcases passed or failed. Ignore warnings about "Presentation errors".


The Siruseri Singing Championship


(Zonal Computing Olympiad 2019)


The Siruseri Singing Championship is going to start, and Lavanya wants to figure out the outcome before the tournament even begins! Looking at past tournaments, she realizes that the judges care only about the pitches that the singers can sing in, and so she devises a method through which she can accurately predict the outcome of a match between any two singers.


She represents various pitches as integers and has assigned a lower limit and an upper limit for each singer, which corresponds to their vocal range. For any singer, the lower limit will always be less than the upper limit. If a singer has lower limit L and upper limit U (L < U), it means that this particular singer can sing in all the pitches between L and U, that is they can sing in the pitches {L, L+1, L+2, …, U}.


The lower bounds and upper bounds of all the singers are distinct. When two singers Si and Sj with bounds (Li, Ui) and (Lj, Uj) compete against each other,

Si wins if they can sing in every pitch that Sj can sing in, and some more pitches. Similarly, Sj wins if they can sing in every pitch that Si can sing in, and


some more pitches. If neither of these conditions are met, the match ends in a draw. In this problem, you can assume that no match ends in a draw.


N singers are competing in the tournament. Each singer competes in N-1 matches, one match against each of the other singers. The winner of a match scores 2 points, and the loser gets no points. But in case of a draw, both the singers get 1 point each.

  1. 15


5 21


Sample output 2


10 4 6 2 12 0 8



Select the Language for this assignment. C++



1 #include<iostream>

  1. #include<vector>

3

4 using namespace std;

5

6 int main()

7 {


  • int n;
  • //Input number of singers


  1. cin>>n;
  2. vector<int> L(n), U(n), S(n);
  3. //Input lower and upper bound for all singers
  4. for(int i = 0; i < n; i++)


  1. {
  2. cin>> L[i] >> U[i];
  3. S[i] = 0;
  4. }

19

  1. for(int i = 0; i < n; i++)
  2. {
  3. for(int j = i + 1; j < n; j++)
  4. {
  5. if(L[i] < L[j] && U[i] > U[j])//Singer Si wins



You may submit any number of times before the due date. The final submission will be considered for grading.


Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program, your assignment will not be graded and you will not see your score after the deadline.