60pts求条玄关
查看原帖
60pts求条玄关
1289619
Fat__Cat楼主2025/6/16 21:03

是WA的,不该输出-1时输出导致错误

#include<bits/stdc++.h>
using namespace std;
int m,n,k,b[100005],cnt;
struct timu{
    int w;
    int v;
}a[100005];
bool check()
{
    for(int i=0;i<m;i++) if(b[i]<k) return 0;
    return 1;
}
bool cmp(timu x,timu y)
{
    return x.v>y.v;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>m>>n>>k;
    for(int i=0;i<n;i++) cin>>a[i].w;
    for(int i=0;i<n;i++) cin>>a[i].v;
    sort(a,a+n,cmp);
    bool f=0;
    int last=-1;
    for(int i=0;i<n;i++)
    {
        if(check())
        {
            f=1;
            cnt=i;
            break;
        }
        if(last==a[i].w-1) continue;
        b[a[i].w-1]+=a[i].v;
        last=a[i].w-1;
    }
    if(check()&&!f)
    {
        f=1;
        cnt=n;
    }
    if(f) cout<<cnt;
    else cout<<-1;
    return 0;
}
2025/6/16 21:03
加载中...