Home Coming
시간 제한0.3초메모리 제한512 MB
과목이 원형으로 배치되어 있고 i번 과목을 통과하려면 i부터 K개의 연속한 교재를 사야 할 때, 상금 합에서 교재 비용을 뺀 값이 최대가 되는 과목 집합을 고른다.
문제
Spiderman is still in high school. Our friendly neighborhood superhero has N subjects at school numbered from 0 to N-1. For each subject Peter passes, he receives a prize in money from Tony Stark. If Peter passes subject number i, he receives Ai dollars.
Passing a subject is unfortunately not that easy. In order to pass he needs to buy some textbooks. Of course, our friendly superhero is very smart, so he doesn’t need any textbook to study, but some teachers just won’t let him pass unless he invests some money in the books. There are N textbooks numbered from 0 to N – 1, the i-th of which costs Bi dollars.
In order to pass subject number i, Peter needs to buy textbooks i, (i + 1) % N, (i + 2) % N, …, (i + K – 1) % N, where K is a given constant.
Peter doesn’t care about school anymore since his dream is to become an Avenger, so it’s not relevant whether he passes all subjects or not. Peter loves time, and time is money, so help Peter make the biggest profit.
제한
Let SN be the sum of all N’s over all calls of solve, and let SNK be the sum of N*K over all calls of solve. Then:
- 1 ≤ K ≤ N ≤ 2,000,000
- 1 ≤ SN ≤ 2,000,000
- 0 ≤ Ai, Bi ≤ 1,000,000,000
힌트
- Given two positive numbers A and B, A % B denotes the remainder of A when divided by B.
- The visible tests will not be grouped with other tests.
예제
이 문제는 공개된 예제가 없습니다.