欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Bubble Cup 11 - Finals [Online Mirror, Div. 2] C. Space Formula

程序员文章站 2022-05-09 21:16:39
...

传送门:    C. Space Formula

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Formula 1 officials decided to introduce new competition. Cars are replaced by space ships and number of points awarded can differ per race.

Given the current ranking in the competition and points distribution for the next race, your task is to calculate the best possible ranking for a given astronaut after the next race. It's guaranteed that given astronaut will have unique number of points before the race.

Input

The first line contains two integer numbers NN (1≤N≤2000001≤N≤200000) representing number of F1 astronauts, and current position of astronaut DD (1≤D≤N1≤D≤N) you want to calculate best ranking for (no other competitor will have the same number of points before the race).

The second line contains NN integer numbers SkSk (0≤Sk≤1080≤Sk≤108, k=1...Nk=1...N), separated by a single space, representing current ranking of astronauts. Points are sorted in non-increasing order.

The third line contains NN integer numbers PkPk (0≤Pk≤1080≤Pk≤108, k=1...Nk=1...N), separated by a single space, representing point awards for the next race. Points are sorted in non-increasing order, so winner of the race gets the maximum number of points.

Output

Output contains one integer number — the best possible ranking for astronaut after the race. If multiple astronauts have the same score after the race, they all share the best ranking.

Example

input

Copy

4 3
50 30 20 10
15 10 7 3

output

Copy

2

Note

If the third ranked astronaut wins the race, he will have 35 points. He cannot take the leading position, but he can overtake the second position if the second ranked astronaut finishes the race at the last position.

问题大意:第一排n个数,每个数分配一个第二排中的一个数,分配之后让第D个数最大(分配之后有若干个数字相等,则第D个数优先(排名靠前));

例子解释:50 +10 30+3 20+15 10+7;     60 35 33 17

首先第D个数再差都是当前的排名,第一排的数字都是非递增数列,所以跟第D个数之前的比就行

代码:

#include <iostream>
#include <algorithm>
using namespace std;

int main(){
    int n,k;
    cin>>n>>k;
    int rank[n];
    for(int i=0;i<n;i++)
        cin>>rank[i];
    int point[n];
    for(int i=0;i<n;i++)
        cin>>point[i];
    rank[k-1]=rank[k-1]+point[0];
    int mark=0;  //默认最后的结果是自己的排名没有变
    for(int i=0;i<k-1;i++){//跟自己之前的比较,后面的不用看
        if(rank[i]+point[n-mark-1]<=rank[k-1]){//能超一个就mark++,最后减一下,就是最后的排名(反例:如果加上最小的还是比我大,那么不管加哪个都会比我大,那还不如让他加上最大的,让别人拿最小的,这样有利于自己最后的排名)
            //cout<<rank[i]+point[n-mark-1]<<" "<<mark<<endl;
            mark++;
        }

    }
    cout<<k-mark;
    return 0;
}