zoukankan      html  css  js  c++  java
  • Bubble Cup 11

    传送门:    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;
    }
    
  • 相关阅读:
    minicom使用
    Oracle(+)号用法
    金蝶AAS对HTTP方法有限制
    Maven设置utf8编码格式
    ELK实时日志分析平台环境部署--完整记录(ElasticSearch+Logstash+Kibana )
    Redis中的持久化操作
    iOS 动画Animation
    iOS打造属于自己的用户行为统计系统
    WEB前端,混合排版,有的宽有的窄,滚动会出现空白处,怎么办。
    hadoop云盘client的设计与实现(一)
  • 原文地址:https://www.cnblogs.com/UUUUh/p/10284026.html
Copyright © 2011-2022 走看看