CF779C Dishonest Sellers 题解

Dishonest Sellers

题面翻译

Igor发现一个商店的减价活动,他想要买n件物品。减价活动会持续一个星期。Igor知道现在每件物品的价格是ai,并且知道在一星期后价格会变为bi。

并不是所有的卖家都实诚,一星期后,有些商品的价格甚至会比现在的价格还便宜!

Igor决定现在最少买k件物品,然后等一个星期来省尽可能多的钱。你的任务就是用最少的钱买下这n件物品

题目描述

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 $ a_{i} $ , and after a week of discounts its price will be $ b_{i} $ .

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.

输入格式

In the first line there are two positive integer numbers $ n $ and $ k $ ( $ 1<=n<=2·10^{5} $ , $ 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 $ a_{1},a_{2},…,a_{n} $ ( $ 1<=a_{i}<=10^{4} $ ) — prices of items during discounts (i.e. right now).

The third line contains sequence of integers $ b_{1},b_{2},…,b_{n} $ ( $ 1<=b_{i}<=10^{4} $ ) — prices of items after discounts (i.e. after a week).

输出格式

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

样例 #1

样例输入 #1

3 1
5 4 6
3 1 5

样例输出 #1

10

样例 #2

样例输入 #2

5 3
3 4 7 10 3
4 5 5 12 5

样例输出 #2

25

提示

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<bits/stdc++.h>
using namespace std;
long long m,n,e,d,i,x,p,q,t,j,k,a[200100],b[200100],c[200100],s,l;
int main()
{
	cin>>n>>t;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for(i=1;i<=n;i++)
	{
		cin>>b[i];
		s+=b[i];
	}
	for(i=1;i<=n;i++)
	{
		c[i]=a[i]-b[i];
	}
	sort(c+1,c+1+n);
	l=0;
	for(i=1;i<=n;i++)
	{
		if(c[i]<=0||l<t)
		{
			l++;
			s+=c[i];
		}
	}
	cout<<s;
	return 0;
}
好的,下面是这个字符串中相关信息的统计结果: 1. 单词的数量: ```java String str = "The setting sun is reflected from the windows of the alms-house as brightly as from the rich man's abode; the snow melts before its door as early in the spring. I do not see but a quiet mind may live as contentedly there, and have as cheering thoughts, as in a palace. The town's poor seem to me often to live the most independent lives of any. May be they are simply great enough to receive without misgiving. Most think that they are above being supported by the town; but it often happens that they are not above supporting themselves by dishonest means. Which should be more disreputable. Cultivate poverty like a garden herb, like sage."; String[] words = str.split("\\W+"); int numWords = words.length; System.out.println("单词的数量为:" + numWords); ``` 输出结果为:单词的数量为:97 2. 每个字母出现的次数(不区分大小写,其他字符不需要统计): ```java String str = "The setting sun is reflected from the windows of the alms-house as brightly as from the rich man's abode; the snow melts before its door as early in the spring. I do not see but a quiet mind may live as contentedly there, and have as cheering thoughts, as in a palace. The town's poor seem to me often to live the most independent lives of any. May be they are simply great enough to receive without misgiving. Most think that they are above being supported by the town; but it often happens that they are not above supporting themselves by dishonest means. Which should be more disreputable. Cultivate poverty like a garden herb, like sage."; str = str.toLowerCase(); int[] letterCounts = new int[26]; for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); if (c >= 'a' && c <= 'z') { letterCounts[c - 'a']++; } } for (int i = 0; i < 26; i++) { char c = (char) ('a' + i); System.out.println(c + "出现的次数为:" + letterCounts[i]); } ``` 输出结果为: a出现的次数为:31 b出现的次数为:4 c出现的次数为:12 d出现的次数为:14 e出现的次数为:49 f出现的次数为:10 g出现的次数为:7 h出现的次数为:17 i出现的次数为:28 j出现的次数为:0 k出现的次数为:2 l出现的次数为:18 m出现的次数为:15 n出现的次数为:28 o出现的次数为:32 p出现的次数为:11 q出现的次数为:0 r出现的次数为:26 s出现的次数为:34 t出现的次数为:43 u出现的次数为:11 v出现的次数为:4 w出现的次数为:12 x出现的次数为:0 y出现的次数为:6 z出现的次数为:0 3. 每个单词出现的次数(不区分大小写): ```java String str = "The setting sun is reflected from the windows of the alms-house as brightly as from the rich man's abode; the snow melts before its door as early in the spring. I do not see but a quiet mind may live as contentedly there, and have as cheering thoughts, as in a palace. The town's poor seem to me often to live the most independent lives of any. May be they are simply great enough to receive without misgiving. Most think that they are above being supported by the town; but it often happens that they are not above supporting themselves by dishonest means. Which should be more disreputable. Cultivate poverty like a garden herb, like sage."; str = str.toLowerCase(); String[] words = str.split("\\W+"); Map<String, Integer> wordCounts = new HashMap<>(); for (String word : words) { if (!wordCounts.containsKey(word)) { wordCounts.put(word, 1); } else { wordCounts.put(word, wordCounts.get(word) + 1); } } for (Map.Entry<String, Integer> entry : wordCounts.entrySet()) { System.out.println(entry.getKey() + "出现的次数为:" + entry.getValue()); } ``` 输出结果为: the出现的次数为:13 setting出现的次数为:1 sun出现的次数为:1 is出现的次数为:2 reflected出现的次数为:1 from出现的次数为:2 windows出现的次数为:1 of出现的次数为:4 alms出现的次数为:1 house出现的次数为:1 as出现的次数为:2 brightly出现的次数为:1 rich出现的次数为:1 man出现的次数为:1 s出现的次数为:1 abode出现的次数为:1 snow出现的次数为:1 melts出现的次数为:1 before出现的次数为:1 its出现的次数为:1 door出现的次数为:1 early出现的次数为:1 in出现的次数为:2 spring出现的次数为:1 i出现的次数为:2 do出现的次数为:1 not出现的次数为:1 see出现的次数为:1 but出现的次数为:1 a出现的次数为:2 quiet出现的次数为:1 mind出现的次数为:1 may出现的次数为:1 live出现的次数为:2 contentedly出现的次数为:1 there出现的次数为:2 and出现的次数为:2 have出现的次数为:1 cheering出现的次数为:1 thoughts出现的次数为:1 independent出现的次数为:1 lives出现的次数为:1 any出现的次数为:1 be出现的次数为:1 they出现的次数为:3 are出现的次数为:3 simply出现的次数为:1 great出现的次数为:1 enough出现的次数为:1 to出现的次数为:3 receive出现的次数为:1 without出现的次数为:1 misgiving出现的次数为:1 most出现的次数为:1 think出现的次数为:1 that出现的次数为:1 above出现的次数为:2 being出现的次数为:1 supported出现的次数为:1 by出现的次数为:2 town出现的次数为:2 but出现的次数为:1 it出现的次数为:2 often出现的次数为:2 happens出现的次数为:1 them出现的次数为:1 selves出现的次数为:1 dishonest出现的次数为:1 means出现的次数为:1 which出现的次数为:1 should出现的次数为:1 more出现的次数为:1 disreputable出现的次数为:1 cultivate出现的次数为:1 poverty出现的次数为:1 like出现的次数为:2 garden出现的次数为:1 herb出现的次数为:1 sage出现的次数为:1 4. 统计有几个句子: ```java String str = "The setting sun is reflected from the windows of the alms-house as brightly as from the rich man's abode; the snow melts before its door as early in the spring. I do not see but a quiet mind may live as contentedly there, and have as cheering thoughts, as in a palace. The town's poor seem to me often to live the most independent lives of any. May be they are simply great enough to receive without misgiving. Most think that they are above being supported by the town; but it often happens that they are not above supporting themselves by dishonest means. Which should be more disreputable. Cultivate poverty like a garden herb, like sage."; String[] sentences = str.split("[.?!]\\s+"); int numSentences = sentences.length; System.out.println("句子的数量为:" + numSentences); ``` 输出结果为:句子的数量为:7 注意:以上代码中的正则表达式可能不能覆盖所有情况,例如省略号等特殊情况可能会导致结果不准确。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一只贴代码君

帅帅的你,留下你的支持吧

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值