zl程序教程

您现在的位置是:首页 >  其它

当前栏目

Acwing第 20 场周赛【未完结】

20 AcWing 周赛
2023-09-11 14:15:52 时间

3994. 水果派【难度: 简单 / 知识点: 模拟】

在这里插入图片描述
https://www.acwing.com/problem/content/3997/

#include<bits/stdc++.h>
using namespace std;
int main(void)
{
    int t; cin>>t;
    while(t--)
    {
        int a,b,c,d,k; cin>>a>>b>>c>>d>>k;
        int cnt1=a/c;
        if(a%c) cnt1++;
        int cnt2=b/d;
        if(b%d) cnt2++;
        if(cnt1+cnt2<=k) cout<<cnt1<<" "<<cnt2<<endl;
        else puts("-1");
    }
    return 0;
}

3995. 最小的和【难度: 一般 / 知识点: 贪心】

在这里插入图片描述https://www.acwing.com/problem/content/3998/
大根堆,每次找最大值让其减1.

#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
const int N=1e5+10;
LL a[N],b[N],n,k,k1,k2;
priority_queue<int>heap;
int main(void)
{
    cin>>n>>k1>>k2;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++) cin>>b[i];
    for(int i=0;i<n;i++)
    {
        heap.push(abs(a[i]-b[i]));
    }
    k=k1+k2;
    while(k--)
    {
        auto temp=heap.top(); heap.pop();
        temp--;
        heap.push(abs(temp));//-1这种情况,就是都为0.但是我们的次数还没用完。
    }
    LL sum=0;
    while(heap.size())
    {
        LL temp=heap.top(); heap.pop();
        sum+=temp*temp;
    }
    cout<<sum;
    return 0;
}