|시간 제한||메모리 제한||제출||정답||맞힌 사람||정답 비율|
|0.3 초||512 MB||2||2||2||100.000%|
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:
The contestant should include the header
The contestant needs to implement the following function:
long long int solve(int N, int K, int *A, int *B);
This function may be called multiple times over the course of a single run.
1 ≤ SN ≤ 500
1 ≤ SN ≤ 5,000
1 ≤ SNK ≤ 2,000,000
No additional constraints.
C++17, C++14, C++20, C++14 (Clang), C++17 (Clang), C++20 (Clang)