zoukankan      html  css  js  c++  java
  • Div2--B. Knights of a Polygonal Table(坑题)

    B. Knights of a Polygonal Table
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power is greater than the power of victim. However, even such a knight will torment his conscience, so he can kill no more than kk other knights. Also, each knight has some number of coins. After a kill, a knight can pick up all victim's coins.

    Now each knight ponders: how many coins he can have if only he kills other knights?

    You should answer this question for each knight.

    Input

    The first line contains two integers nn and kk (1n105,0kmin(n1,10))(1≤n≤105,0≤k≤min(n−1,10)) — the number of knights and the number kk from the statement.

    The second line contains nn integers p1,p2,,pnp1,p2,…,pn (1pi109)(1≤pi≤109) — powers of the knights. All pipi are distinct.

    The third line contains nn integers c1,c2,,cnc1,c2,…,cn (0ci109)(0≤ci≤109) — the number of coins each knight has.

    Output

    Print nn integers — the maximum number of coins each knight can have it only he kills other knights.

    Examples
    input
    Copy
    4 2
    4 5 9 7
    1 2 11 33
    
    output
    Copy
    1 3 46 36 
    input
    Copy
    5 1
    1 2 3 4 5
    1 2 3 4 5
    
    output
    Copy
    1 3 5 7 9 
    input
    Copy
    1 0
    2
    3
    
    output
    Copy
    3 
    Note

    Consider the first example.

    • The first knight is the weakest, so he can't kill anyone. That leaves him with the only coin he initially has.
    • The second knight can kill the first knight and add his coin to his own two.
    • The third knight is the strongest, but he can't kill more than k=2k=2 other knights. It is optimal to kill the second and the fourth knights: 2+11+33=462+11+33=46.
    • The fourth knight should kill the first and the second knights: 33+1+2=3633+1+2=36.

    In the second example the first knight can't kill anyone, while all the others should kill the one with the index less by one than their own.

    In the third example there is only one knight, so he can't kill anyone.

    题意:n个骑士,每个骑士可以杀死比他武力值低的骑士,并获得他杀死的骑士的金币,每个骑士最多杀死k个骑士,输出每个骑士最大金币数

    思路:排序加暴力  时间 O(1e5 * n *lgn )数据大 用long long

    #include <bits/stdc++.h>
    
    using namespace std;
    
    const int maxn = 1e5+5;
    
    typedef long long ll;
    
    struct node{
        ll val,id,power,v;
    }ss[maxn];
    
    int v[15],pos;
    
    int cmp(node x,node y)
    {
        return x.power<y.power;
    }
    
    int cmp1(node x,node y)
    {
        return x.id<y.id;
    }
    
    int cmp2(int x,int y)
    {
        return x>y;
    }
    
    int main()
    {
        int x,y;
        scanf("%d %d",&x,&y);
        for(int i = 0;i<x;i++){
            scanf("%lld",&ss[i].power);
            ss[i].id = i;
        }
        for(int i = 0;i<x;i++){
            scanf("%lld",&ss[i].val);
        }
        pos = -1;
        sort(ss,ss+x,cmp);
        memset(v,0,sizeof(v));
        for(int i = 0;i<x;i++){
            if(pos != 10 ){
                pos ++;
            }
            sort(v,v+pos+1,cmp2);
            ss[i].v = 0;
            for(int j = 0;j < y && j < pos;j++){
                ss[i].v += v[j];
            }
            ss[i].v += ss[i].val;
            v[pos] = ss[i].val > v[pos] ? ss[i].val : v[pos] ;
        }
        sort(ss,ss + x,cmp1);
        for (int i = 0;i<x;i++){
            printf("%lld ",ss[i].v);
        }
        return 0;
    }
    

     

  • 相关阅读:
    CEIWEI CommTone串口调试精灵7.1 串口调试 串口工具
    CEIWEI USBMonitor USB监控精灵 v2.3.2 USB过滤驱动 USB监控
    CommMonitor8.0 串口过滤驱动 SDK DLL版本 C#/Delphi调用DEMO
    CommMonitor10.0.3串口过滤工具(serial port monitor)
    (1)、JEasyUI 之 Datagrid的Combobox 显示 textField 值的问题
    button 使用 flex 布局的兼容性问题
    探索 Reflect.apply 与 Function.prototype.apply 的区别
    awk 输出前 N 列的最简单方法
    在 Ubuntu 18.04 下安装 fcitx 及搜狗拼音输入法
    禁用 Gnome Shell 默认的 Ubuntu Dock 和 Ubuntu AppIndicators 扩展
  • 原文地址:https://www.cnblogs.com/Nlifea/p/11745989.html
Copyright © 2011-2022 走看看