IITian and Course Tagging.

3.4

19 votes
Problem

As we all know, due to the new rules we M.Techs can benefit from course tagging. However the institute has now allowed every department to frame their own rules for course tagging and subsequent CPI updation. So your friend Vinod (you guessed it right, his motto in life is "WIN against all ODDs") from Completely Secret Engineering Department has asked you for some help. He says that his department has laid down the following procedure for course tagging along with appointing a panel for course tagging.

  • The student submits the grades for all the courses he has completed to the panel.
  • The panel then scales all the grades to a 100 marks system as per the rules laid by the department.
  • The panel then randomly removes the grades of two of the courses from the list.
  • The best two courses are then selected for calculating the CPI.

Vinod has come to you with the scaled marks (i.e. marks out of 100 in all his 'N' courses). He also has a fair idea of the way in which the professors in the panel remove two subjects. So, he now wants you to quickly compute the total marks of the best two subjects in 'M' of the cases that can possibly occur according to him. Each of the 'M' cases contain two numbers 'a' and 'b' of the indicating the course numbers from the list whose marks are removed by the panel before selecting the best two for CPI.

Input Format:
The first line of each input file consists of 'N', the number of courses and 'M' queries , the number of possible ways in which two subjects can be removed where each query consists of two space separated integers 'a', 'b' indicating the position of the courses in the list whose grades are removed.

Output Format:
For each test case output 'M' lines,
The 'i'th line should contain the answers to the 'i'th query.

Constraints:
2<=N<=100000 (10^5)
1<=M<=100000 (10^5)
1<=a,b<=N

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?