CF#779 C. Dishonest Sellers(贪心)

本文介绍了一个购物问题,通过分析物品在折扣期间与折扣后的价格变化,采用贪心算法找到最小花费方案。具体而言,该问题涉及如何选择购买商品的时间点以实现成本最小化。
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·1050 ≤ 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.


题意:有n件物品,其价格分别为a1,a2,...,an,从中买至少k个物品,再以价格b1,b2,...bn买剩余没买的物品,求最小花费。

思路:贪心的买ai与bi差价最大的物品。。。

#include<bits/stdc++.h>
using namespace std;
const int N = 1e6;
struct item
{
    int a,b,x;
} f[N];
int cmp(xx u,xx v)
{
    return u.x<v.x;
}
int main()
{
    int n,k;
    while(scanf("%d%d",&n,&k)==2)
    {
        int sum=0;
        for(int i=0; i<n; i++)
            scanf("%d",&f[i].a);
        for(int i=0; i<n; i++)
        {
            scanf("%d",&f[i].b);
            f[i].x=f[i].a-f[i].b;
        }
        sort(f,f+n,cmp);
        for(int i=0,w=0;i<n;i++)
        {
            if(f[i].x<=0)
            {
                sum+=f[i].a;
                w++;
            }
            else
            {
                if(w<k)
                    sum+=f[i].a,w++;
                else
                    sum+=f[i].b;
            }
        }
        printf("%d\n",sum);
    }
}




如何实现Vue锚点组件的tab栏切换逻辑?以下为标签template代码<template> <div class="charts-container"> <!-- 统计分析悬浮栏 --> <div class="stat-floating-bar"> <!-- 调试信息显示 --> <div style="font-size: 10px; color: #999; margin-bottom: 10px; text-align: center; padding: 5px; background: rgba(0,0,0,0.05); border-radius: 4px;"> <div>当前状态: {{ statType }}</div> <div>滚动监听: ✅</div> <div style="margin-top: 5px;"> <el-button size="mini" type="info" @click="testScrollListener">测试监听</el-button> </div> </div> <div class="stat-tab" :class="{ active: statType === 'personnel' }" @click="scrollToSection('personnel')"> <el-icon><User /></el-icon> <span>人员统计</span> </div> <div class="stat-tab" :class="{ active: statType === 'violation' }" @click="scrollToSection('violation')"> <el-icon><Warning /></el-icon> <span>违规人员统计</span> </div> <div class="stat-tab" :class="{ active: statType === 'dishonest' }" @click="scrollToSection('dishonest')"> <el-icon><CircleClose /></el-icon> <span>失信人员统计</span> </div> </div> <!-- 人员统计区域 --> <div id="personnel-section" class="stat-section"> <div class="header"> <div class="header-title">人员统计</div> <div class="refresh-controls"> <el-button type="primary" size="small" @click="forceReinitCharts('personnel')" :loading="isRefreshing.personnel" > <el-icon><Refresh /></el-icon> 刷新图表 </el-button> </div> </div> <div class="chart-grid"> <!-- 人员统计的4个图表 --> <div class="chart-item"> <div ref="personnelPersonnelTypeChart" class="chart"></div> </div> <div class="chart-item"> <div ref="personnelPositionLevelChart" class="chart"></div> </div> <div class="chart-item"> <div ref="personnelRegionChart" class="chart"></div> </div> <div class="chart-item"> <div ref="personnelGenderChart" class="chart"></div> </div> </div> </div> <!-- 违规人员统计区域 --> <div id="violation-section" class="stat-section"> <div class="header"> <div class="header-title">违规人员统计</div> <div class="refresh-controls"> <el-button type="primary" size="small" @click="forceReinitCharts('violation')" :loading="isRefreshing.violation" > <el-icon><Refresh /></el-icon> 刷新图表 </el-button> </div> </div> <div class="chart-grid"> <!-- 违规人员统计的4个图表 --> <div class="chart-item"> <div ref="violationPersonnelTypeChart" class="chart"></div> </div> <div class="chart-item"> <div ref="violationPositionLevelChart" class="chart"></div> </div> <div class="chart-item"> <div ref="violationRegionChart" class="chart"></div> </div> <div class="chart-item"> <div ref="violationGenderChart" class="chart"></div> </div> </div> </div> <!-- 失信人员统计区域 --> <div id="dishonest-section" class="stat-section"> <div class="header"> <div class="header-title">失信人员统计</div> <div class="refresh-controls"> <el-button type="primary" size="small" @click="forceReinitCharts('dishonest')" :loading="isRefreshing.dishonest" > <el-icon><Refresh /></el-icon> 刷新图表 </el-button> </div> </div> <div class="chart-grid"> <!-- 失信人员统计的4个图表 --> <div class="chart-item"> <div ref="dishonestPersonnelTypeChart" class="chart"></div> </div> <div class="chart-item"> <div ref="dishonestPositionLevelChart" class="chart"></div> </div> <div class="chart-item"> <div ref="dishonestRegionChart" class="chart"></div> </div> <div class="chart-item"> <div ref="dishonestGenderChart" class="chart"></div> </div> </div> </div> </div> </template>
08-27
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值