Humans vs AI

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

요약
한 시행의 h와 a를 맞바꿔도 인간 점수가 AI 점수의 k배 이상으로 유지되는 비어 있지 않은 연속 부분 배열의 개수를 센다.
난이도

어려움10점 중 8점

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

문제

In the world of rising AI, James is scared of losing his job. So, when his boss asks him to evaluate a new AI model to see how well it performs compared to humans, he wants to make it look as bad as possible.

To test the AI, James conducts a sequence of NN trials where a human and an AI are given the same task and then scored based on their performance on the task. He is then going to send the results of some non-empty contiguous subsequence of these trials to his boss and quietly delete the rest.

Let a_ia\_i and h_ih\_i be the performance of the AI and human on trial ii, respectively. James's boss evaluates the AI on a sequence of trials by calculating two total scores: one for the humans, and one for the AI. Both scores are initially 00. For each trial ii where h_i≥a_ih\_i \geq a\_i, the boss awards the humans h_i−a_ih\_i-a\_i points. For each trial where h_i<a_ih\_i < a\_i, the AI earns a_i−h_ia\_i-h\_i points. If the humans' total score is greater than or equal to the AI's total score times some constant kk (to account for humans needing food, water, and a desk), James's boss declares that the humans outperform the AI.

James plans to send his chosen subsequence of test results through email to his boss. There is, however, one complication: since AI is already all-knowing and all-pervasive, it intercepts this email and may swap the value of h_ih\_i and a_ia\_i for one trial ii of its choice. (It doesn't want to swap more than one trial result---James might notice!)

Count how many non-empty contiguous subsequences of trial results James could send his boss with the guarantee that humans will be declared to outperform the AI, even if the AI swaps the result of up to one trial.

입력

The first line of input contains two space-separate integers: NN (1≤N≤2⋅1051 \leq N \leq 2 \cdot 10^5), the total number of trials James conducted, and kk (1≤k≤1001 \leq k \leq 100), the multiplier James's boss will apply to the AI's total score to determine whether humans outperform AI.

The second line contains NN space-separated integers h_1,h_2,…,h_Nh\_1, h\_2, \ldots, h\_N (0≤h_i≤1060 \leq h\_i \leq 10^6), the performance of the humans on each of the NN trials.

The third line contains NN space-separated integers a_1,a_2,…,a_Na\_1, a\_2, \ldots, a\_N (0≤a_i≤1060 \leq a\_i \leq 10^6), the performance of the AI on the NN trials.

출력

Print the number of non-empty contiguous trial subsequences for which James's boss would declare that humans outperform AI, even if the AI swaps the result of up to one trial.

예제2

  1. 예제 1

    입력
    10 2
    3 5 7 6 8 6 4 5 2 6
    2 4 6 5 4 3 3 6 3 4
    
    예상 출력
    4
    
  2. 예제 2

    입력
    7 1
    4 3 2 1 7 6 5
    4 2 3 1 7 6 5
    
    예상 출력
    11