当前位置:网站首页>A. Strange Birthday Party- Codeforces Round #694 (Div. 1)
A. Strange Birthday Party- Codeforces Round #694 (Div. 1)
2022-07-30 02:30:00 【秦小咩】
Problem - 1470A - Codeforces
A. Strange Birthday Party
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Petya organized a strange birthday party. He invited nn friends and assigned an integer kiki to the ii-th of them. Now Petya would like to give a present to each of them. In the nearby shop there are mm unique presents available, the jj-th present costs cjcj dollars (1≤c1≤c2≤…≤cm1≤c1≤c2≤…≤cm). It's not allowed to buy a single present more than once.
For the ii-th friend Petya can either buy them a present j≤kij≤ki, which costs cjcj dollars, or just give them ckicki dollars directly.
Help Petya determine the minimum total cost of hosting his party.
Input
The first input line contains a single integer tt (1≤t≤1031≤t≤103) — the number of test cases.
The first line of each test case contains two integers nn and mm (1≤n,m≤3⋅1051≤n,m≤3⋅105) — the number of friends, and the number of unique presents available.
The following line contains nn integers k1,k2,…,knk1,k2,…,kn (1≤ki≤m1≤ki≤m), assigned by Petya to his friends.
The next line contains mm integers c1,c2,…,cmc1,c2,…,cm (1≤c1≤c2≤…≤cm≤1091≤c1≤c2≤…≤cm≤109) — the prices of the presents.
It is guaranteed that sum of values nn over all test cases does not exceed 3⋅1053⋅105, and the sum of values mm over all test cases does not exceed 3⋅1053⋅105.
Output
For each test case output a single integer — the minimum cost of the party.
Examples
input
Copy
2 5 4 2 3 4 3 2 3 5 12 20 5 5 5 4 3 2 1 10 40 90 160 250
output
Copy
30 190
input
Copy
1 1 1 1 1
output
Copy
1
Note
In the first example, there are two test cases. In the first one, Petya has 55 friends and 44 available presents. Petya can spend only 3030 dollars if he gives
- 55 dollars to the first friend.
- A present that costs 1212 dollars to the second friend.
- A present that costs 55 dollars to the third friend.
- A present that costs 33 dollars to the fourth friend.
- 55 dollars to the fifth friend.
In the second one, Petya has 55 and 55 available presents. Petya can spend only 190190 dollars if he gives
- A present that costs 1010 dollars to the first friend.
- A present that costs 4040 dollars to the second friend.
- 9090 dollars to the third friend.
- 4040 dollars to the fourth friend.
- 1010 dollars to the fifth friend.
=========================================================================
很巧妙的贪心,突破点在于c是递增的,这也就说明了,k大的,它能选便宜的也能选送金额大的钱。k小的,它能选便宜的,也能送金额小的。由于我们尽可能选c小的,尽量多的选小的。如果让k小的先选,那么不仅浪费了它能选小的机会,还挤占了k大的选小的机会。所以先选k大的,充分利用
# include<bits/stdc++.h>
# define mod 10
using namespace std;
typedef long long int ll;
ll c[300000+10];
int k[300000+10];
bool cmp(int a,int b)
{
return a>b;
}
int main ()
{
int t;
cin>>t;
while(t--)
{
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>k[i];
}
for(int i=1;i<=m;i++)
{
cin>>c[i];
}
//k小的,买的礼物便宜,送钱少,但之能采用其中一个
//k大的,买的礼物可以贵也可以便宜,送钱多
int now=1;
sort(k+1,k+1+n,cmp);
ll ans=0;
for(int i=1;i<=n;i++)
{
if(now==n+1||c[now]>=c[k[i]])
{
ans+=c[k[i]];
}
else
{
ans+=c[now];
now++;
}
}
cout<<ans<<'\n';
}
return 0;
}
边栏推荐
- Is it difficult for AI to land?Cloud native helps enterprises quickly apply machine learning MLOps
- AI落地难?云原生助力企业快速应用机器学习 MLOps
- Successfully resolved AttributeError: 'PngImageFile' object has no attribute 'imshow'
- tcp ip
- API interface batch test
- RAII Technology Learning
- ESP8266 +0.96“ I2C OLED 表盘时钟
- Docker一键安装MySQL
- matlab用dde23求解带有固定时滞的时滞微分方程
- The box office broke 790 million US dollars. Have you watched this recent dinosaur movie?
猜你喜欢
随机推荐
Is it difficult for AI to land?Cloud native helps enterprises quickly apply machine learning MLOps
解决:npm ERR code ELIFECYCLE npm ERR errno 1(安装脚手架过程中,在npm run dev 时发生错误)
重写并自定义依赖的原生的Bean方法
记一次搭建conda虚拟环境
CVPR 2022 Best Paper -- Learning to Solve Hard Minimal Problems
【笔记】结巴分词绘制词云图
【2023海康威视提前批笔试题】~ 题目及参考答案
奥比中光高级副总裁王兆民离职 董事会秘书暂未取得资格证
博客搭建十:hugo博客添加友链
JS develops 3D modeling software
测试/开发程序员面试该如何谈薪资待遇呢?突破这个坎......
STM32L4R9ZIY6PTR STM32L4 high-performance embedded-MCU
Detailed explanation of carousel picture 2 - carousel pictures through left positioning
flutter学习之widget的显示和隐藏
一个塑料瓶的海洋“奇幻漂流”
Using ESP32 construct a ZIGBEE network adapter
复旦-华盛顿大学EMBA科创的奥E丨《神奇的材料》与被塑造的我们
RAII技术学习
Oracle超全SQL,细节狂魔
The role of interface testing









