zoukankan      html  css  js  c++  java
  • AC日记——Dishonest Sellers Codeforces 779c

    C. Dishonest Sellers
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Igor found out discounts in a shop and decided to buy n items. Discounts at the store will last for a week and Igor knows about each item that its price now is ai, and after a week of discounts its price will be bi.

    Not all of sellers are honest, so now some products could be more expensive than after a week of discounts.

    Igor decided that buy at least k of items now, but wait with the rest of the week in order to save money as much as possible. Your task is to determine the minimum money that Igor can spend to buy all n items.

    Input

    In the first line there are two positive integer numbers n and k (1 ≤ n ≤ 2·105, 0 ≤ k ≤ n) — total number of items to buy and minimal number of items Igor wants to by right now.

    The second line contains sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 104) — prices of items during discounts (i.e. right now).

    The third line contains sequence of integers b1, b2, ..., bn (1 ≤ bi ≤ 104) — prices of items after discounts (i.e. after a week).

    Output

    Print the minimal amount of money Igor will spend to buy all n items. Remember, he should buy at least k items right now.

    Examples
    input
    3 1
    5 4 6
    3 1 5
    output
    10
    input
    5 3
    3 4 7 10 3
    4 5 5 12 5
    output
    25
    Note

    In the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10.

    In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week of discounts, he will pay 5 for it. In total he will spend 3 + 4 + 10 + 3 + 5 = 25.

     思路;

      计算价值然后排序水过(至少k个不是共k个);

    来,上代码:

    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    
    #define maxn 200005
    
    using namespace std;
    
    struct SortNodeType {
        int ai,bi,vi;
    };
    struct SortNodeType item[maxn];
    
    int if_z,n,k,ans;
    
    char Cget;
    
    inline void in(int &now)
    {
        now=0,if_z=1,Cget=getchar();
        while(Cget>'9'||Cget<'0')
        {
            if(Cget=='-') if_z=-1;
            Cget=getchar();
        }
        while(Cget>='0'&&Cget<='9')
        {
            now=now*10+Cget-'0';
            Cget=getchar();
        }
        now*=if_z;
    }
    
    bool cmp(struct SortNodeType a,struct SortNodeType b)
    {
        if(a.vi!=b.vi) return a.vi<b.vi;
        else
        {
            return a.ai<b.ai;
        }
    }
    
    int main()
    {
        in(n),in(k);
        for(int i=1;i<=n;i++) in(item[i].ai);
        for(int i=1;i<=n;i++)
        {
            in(item[i].bi);
            item[i].vi=item[i].ai-item[i].bi;
        }
        sort(item+1,item+n+1,cmp);
        int pos=0;
        for(int i=1;i<=n;i++)
        {
            if(item[i].vi<=0) pos++;
            else break;
        }
        k=max(k,pos);
        for(int i=1;i<=k;i++) ans+=item[i].ai;
        for(int i=k+1;i<=n;i++) ans+=item[i].bi;
        cout<<ans;
        return 0;
    }
  • 相关阅读:
    vss的ss.ini丢失或损坏导致的vss无法登录错误
    NHibernate各种数据库连接参数文件配置方法说明
    oracle操作语句
    企业微信群聊机器人发送本地图片
    securecrt 或xshell 转发80端口
    SecureCRT 或 XSHELL 转发 X11 图形化GUI
    Windows 创建 .gdbinit 提示必须键入文件名
    vscode C++ 程序 windows
    vscode C++ 程序 windows
    解决source insight 4.0 不识别.cc文件的问题
  • 原文地址:https://www.cnblogs.com/IUUUUUUUskyyy/p/6551080.html
Copyright © 2011-2022 走看看