Darts for Programmers

시간 제한2초메모리 제한2048 MB

요약
고정된 20개 웨지 판에서 세 개의 다트 웨지 번호가 주어질 때, 다트 사이 세 원호 중 웨지 값 합이 최대인 것을 계산합니다.
난이도

보통10점 중 4점

유형
배열, 누적 합, 구현
정답자
아직 제출이 없습니다

문제

After a long day of programming challenges, you decide to relax with your friends by playing darts. The only problem is that none of your friends (nor the author) have any clue how scoring works! Rather than try to learn, you simply devise your own rules. The rules you come up with are as follows:

  • Each player throws 33 darts at the board on their turn.
  • The score for that player's turn is the largest sum of the wedge numbers around the dart board between two circularly adjacent darts, including the wedges the darts land in.
  • If two darts land in the same wedge, xx, the sum around the dartboard from xx to xx is xx.
  • If all three darts land in the same wedge, the score for that turn is the number of the wedge they all land in.
  • Nobody is accurate enough to hit the bullseye, so we can safely ignore it.

For example, if your darts land in wedges 11, 1010, and 77 on your turn, you would calculate the sum around the dart board from wedge 11 through wedge 1010 (1+18+4+13+6+10=521 + 18 + 4 + 13 + 6 + 10 = 52), the sum around the dart board from wedge 1010 through wedge 77 (10+15+2+17+3+19+7=7310 + 15 + 2 + 17 + 3 + 19 + 7 = 73) and the sum around the dart board from wedge 77 through wedge 11 (7+16+8+11+14+9+12+5+20+1=1037 + 16 + 8 + 11 + 14 + 9 + 12 + 5 + 20 + 1 = 103). The sum around the dart board from wedge 77 through wedge 11 is the largest sum, so your score would be 103103 points.

The order of the wedges on the dartboard, starting from the top and going clockwise, is 2020, 11, 1818, 44, 1313, 66, 1010, 1515, 22, 1717, 33, 1919, 77, 1616, 88, 1111, 1414, 99, 1212, 55.

입력

The first line contains a single integer NN, representing the number of players.

The subsequent NN lines each contain three (33) space-separated integers w_1w\_1, w_2w\_2, and w_3w\_3 (in that order). Each w_iw\_i represents the wedge number that the ithi^\text{th} dart for that player landed in.

출력

The output should contain NN lines. Each line should contain the score for the corresponding player, in the same order in which they appear in the input.

제한

  • 0<N≤100 0000 < N \leq 100\ 000.
  • All w_iw\_i is guaranteed to be between 11 and 2020, inclusive.

예제1

  1. 예제 1

    입력
    3
    1 4 8
    5 17 11
    9 9 2
    
    예상 출력
    120
    111
    115