10.6模拟赛

· · 个人记录

T1

:::info[题目]{open} U735910 冒险挑战 ::: :::error[WA代码]

#include<bits/stdc++.h>
using namespace std;
const int N=1e9+10;
int a[N];
int n,k,m;
bool cmp(int x,int y){
    return x>y;
}
int main()
{
//  freopen(".in","r",stdin);
//  freopen(".out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>k;
    int ans=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        ans+=a[i]/k;
        a[i]%=k;
    }
    sort(a+1,a+1+n,cmp);
    cin>>m; 
    for(int i=1;i<=n;i++){
        int need=k-a[i]%k;
        if(need>m){
            m-=need;
            break;  
        }
        else{
            m-=need;
            ans++;
        }
    }
    if(m>0) ans+=m/k;
    cout<<ans;
    return 0;
}

::: :::warning[错因] 数组开大了,\textcolor{#052242}{MLE}了 :::

T2

:::info[题目]{open}

:::