C. Dishonest Sellers - Codeforces Round #402 (Div. 2)

本文介绍了一个购物折扣策略问题:Igor需要购买n件商品,在折扣周内至少买k件以节省开支。文章通过算法分析了如何在当前折扣和一周后的价格间做出最优选择,确保Igor能以最低成本购齐所需商品。

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.

#include<stdio.h>
#include<algorithm>
#define MAX_N 200010
using namespace std;
typedef pair<int,int> P;
bool used[MAX_N];
P a[MAX_N],b[MAX_N];
int ttt[MAX_N];

int main()
{
    int N,K;
    scanf("%d%d",&N,&K);
    for(int i=0;i<N;i++){
        scanf("%d",&a[i].first);
        a[i].second=i;
    }
    int ans=0;
    for(int i=0,g;i<N;i++){
        scanf("%d",&b[i].first);
        if(a[i].first<=b[i].first){
            ans+=a[i].first;
            used[a[i].second]=true;
            K--;
        }
        else {
            ttt[a[i].second]=a[i].first;
            a[i].first-=b[i].first;
        }
        b[i].second=i;
    }
    sort(a,a+N);

    for(int i=0;K>0;i++){
        if(used[a[i].second]) continue;
        ans+=ttt[a[i].second];
        used[a[i].second]=true;
        K--;
    }
    for(int i=0;i<N;i++)
        if(!used[b[i].second])
            ans+=b[i].first;
    printf("%d\n",ans);
    return 0;
}
如何实现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 === &#39;personnel&#39; }" @click="scrollToSection(&#39;personnel&#39;)"> <el-icon><User /></el-icon> <span>人员统计</span> </div> <div class="stat-tab" :class="{ active: statType === &#39;violation&#39; }" @click="scrollToSection(&#39;violation&#39;)"> <el-icon><Warning /></el-icon> <span>违规人员统计</span> </div> <div class="stat-tab" :class="{ active: statType === &#39;dishonest&#39; }" @click="scrollToSection(&#39;dishonest&#39;)"> <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(&#39;personnel&#39;)" :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(&#39;violation&#39;)" :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(&#39;dishonest&#39;)" :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
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值