• Codeforces Round #415 (Div. 2) B. Summer sell-off


    http://codeforces.com/contest/810/problem/B

    B. Summer sell-off
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant.

    Shop, where Noora is working, has a plan on the following n days. For each day sales manager knows exactly, that in i-th day ki products will be put up for sale and exactly li clients will come to the shop that day. Also, the manager is sure, that everyone, who comes to the shop, buys exactly one product or, if there aren't any left, leaves the shop without buying anything. Moreover, due to the short shelf-life of the products, manager established the following rule: if some part of the products left on the shelves at the end of the day, that products aren't kept on the next day and are sent to the dump.

    For advertising purposes manager offered to start a sell-out in the shop. He asked Noora to choose any fdays from n next for sell-outs. On each of f chosen days the number of products were put up for sale would be doubled. Thus, if on i-th day shop planned to put up for sale ki products and Noora has chosen this day for sell-out, shelves of the shop would keep ki products. Consequently, there is an opportunity to sell two times more products on days of sell-out.

    Noora's task is to choose f days to maximize total number of sold products. She asks you to help her with such a difficult problem.

    Input

    The first line contains two integers n and f (1 ≤ n ≤ 105, 0 ≤ f ≤ n) denoting the number of days in shop's plan and the number of days that Noora has to choose for sell-out.

    Each line of the following n subsequent lines contains two integers ki, li (0 ≤ ki, li ≤ 109) denoting the number of products on the shelves of the shop on the i-th day and the number of clients that will come to the shop on i-th day.

    Output

    Print a single integer denoting the maximal number of products that shop can sell.

    Examples
    input
    4 2
    2 1
    3 5
    2 3
    1 5
    output
    10
    input
    4 1
    0 2
    0 3
    3 5
    0 6
    output
    5
    Note

    In the first example we can choose days with numbers 2 and 4 for sell-out. In this case new numbers of products for sale would be equal to [2, 6, 2, 2] respectively. So on the first day shop will sell 1 product, on the second — 5, on the third — 2, on the fourth — 2. In total 1 + 5 + 2 + 2 = 10 product units.

    In the second example it is possible to sell 5 products, if you choose third day for sell-out.

     题意:每一天有k产品和l顾客,如果可以有f天的产品可以翻倍,那么最后卖出的总的销售量是多少?

     题解:定义结构体中的数据k,l,count(加倍可以增加的量)。则根据count排序,给前f天产品翻倍。然后遍历一遍,每次输出能够卖掉的产品数量。

    #include<bits/stdc++.h>
    using namespace std;
    const int N=1e5+7;
    struct node
    {
        long long  k,l;
        long long count; 
    }day[N];
    bool cmp(node a,node b)      //按照翻倍后多余的量排序 
    {
        return a.count>b.count; 
    } 
    int main() 
    {
        int n,f;
        cin>>n>>f;
        for(int i=1;i<=n;i++)
        {
            cin>>day[i].k>>day[i].l;
            if(day[i].k<day[i].l)
            {
                if(day[i].k*2<day[i].l)
                    day[i].count=day[i].k;
                else 
                    day[i].count=day[i].l-day[i].k; 
            }
            else 
                day[i].count=0; 
        }
        long long ans=0; 
        sort(day+1,day+n+1,cmp);     //根据能多卖出的产品数排序 
        for(int i=1;i<=n;i++)
        {
            if(f)     //把能卖出最大的天数,产品翻倍后在卖 
            {
                f--;
                day[i].k=day[i].k*2;
            }
            if(day[i].k>day[i].l)
                ans+=day[i].l;
            else 
                ans+=day[i].k;
        }
        cout<<ans<<endl; 
        
        return 0; 
    } 
    漫天星辰,繁华时下。心中冷淡,一笑奈何。
  • 相关阅读:
    网页链接在 什么时候 进行跳转到哪里?
    word中那些重要但是被人忽略的快捷键和长word文档的跳转
    如何在editplus中配置ctags?
    winsow xp不能安装软件, 提示"中断" 是因为设置了 软件限制策略
    firefox的plugin-container.exe进程如何关闭?
    thinkphp的url地址区分大小写?
    thinkphp单入口和多入口的访问方法
    什么时候使用tab键来对齐代码和代码的风格
    该不该用inline-block取代float? inline和float的区别?
    cad中关于点样式点的绘制
  • 原文地址:https://www.cnblogs.com/Scalpel-cold/p/7193672.html
Copyright © 2020-2023  润新知