Codeforces Round #652 (Div. 2) C—RationalLee 构造+贪心

Posted qingyuyyyyy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #652 (Div. 2) C—RationalLee 构造+贪心相关的知识,希望对你有一定的参考价值。

比赛的时候wa吐了

#include<map>
#include<queue>
#include<time.h>
#include<limits.h>
#include<cmath>
#include<ostream>
#include<iterator>
#include<set>
#include<stack>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define rep_1(i,m,n) for(int i=m;i<=n;i++)
#define mem(st) memset(st,0,sizeof st)
int read()
{
    int res=0,ch,flag=0;
    if((ch=getchar())==-)             //判断正负
        flag=1;
    else if(ch>=0&&ch<=9)           //得到完整的数
        res=ch-0;
    while((ch=getchar())>=0&&ch<=9)
        res=res*10+ch-0;
    return flag?-res:res;
}
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef pair<double,double> pdd;
const int inf = 0x3f3f3f3f;
const int N=2e5+10;
#define int long long
int a[N];
int num[N];
bool st[N];
bool cmp(int a,int b)
{
    return a>b;
}
void solve()
{
    memset(st,0,sizeof st);
    int n,k;
    cin>>n>>k;
    for(int i=1; i<=n; i++)
        cin>>a[i];
    for(int i=1; i<=k; i++)
        cin>>num[i];

    sort(a+1,a+1+n,cmp);
    sort(num+1,num+1+k);
    int sum=0;
    for(int i=1;i<=k;i++)
    {
        sum+=a[i];
        num[i]--;
        if(num[i]==0)
            sum+=a[i];
    }
    ll pos=k+1;
    for(int i=1;i<=k;i++)
    {
        if(num[i]==0)
            continue;
        sum+=a[pos+num[i]-1];
        pos+=num[i];
    }
    cout<<sum<<endl;
}
signed main()
{
    int t;
    cin>>t;
    while(t--)
        solve();
    return 0;
}

 

以上是关于Codeforces Round #652 (Div. 2) C—RationalLee 构造+贪心的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #652 (Div. 2) D. TediousLee

Codeforces Round #652 (Div. 2) C—RationalLee 构造+贪心

Codeforces Round #652 (Div. 2) E. DeadLee(贪心)

Codeforces Round #652 (Div. 2) C. RationalLee(贪心)

Codeforces Round #652 (Div. 2) B. AccurateLee(字符串)

Codeforces Round #652 (Div. 2) E. DeadLee 贪心