시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB165736445.714%

문제

Your favorite football team is playing a charity tournament, which is part of a worldwide fundraising effort to help children with disabilities. As in a normal tournament, three points are awarded to the team winning a match, with no points to the losing team. If the game is drawn, each team receives one point.

Your team played N matches during the first phase of the tournament, which has just finished. Only some teams, the ones with more accumulated points, will advance to the second phase of the tournament. However, as the main objective of the tournament is to raise money, before the set of teams that will pass to the second phase is determined, each team is allowed to buy additional goals. These new goals count as normally scored goals, and may be used to alter the result of any of the matches the team played.

Your team’s budget is enough to buy up to G goals. Can you tell the maximum total number of points your team can get after buying the goals, supposing the other teams will not buy any goals?

입력

The first line contains two integers N (1 ≤ N ≤ 105) and G (0 ≤ G ≤ 106) representing respectively the number of matches your team played and the number of goals your team can buy. Each of the next N lines describes a match result with two integers S and R (0 ≤ S, R ≤ 100), indicating respectively the goals your team scored and received on that match before buying goals.

출력

Output a line with an integer representing the maximum total number of points your team can get after buying the goals.

예제 입력 1

2 1
1 1
1 1

예제 출력 1

4

출처

ICPC > Regionals > Latin America > Latin America Regional Contests 2013 F번

  • 문제를 만든 사람: Leopoldo Taravilse