洛谷 P1190 [NOIP 2010 普及组] 接水问题

贪心,不断的更新前m个水龙头占用时间,每次把前m个水龙头进行排序,取最小,加上排队的第一个人的耗时,不断重复步骤即可,最后输出m个水龙头的最大占用时间。

AcCode:

#include<iostream>
#include<algorithm>
using namespace std;
int a[10010];
int main(){
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < n; i++) cin >> a[i];
    int p = m;
    for(; p < n; p++){
        sort(a, a + m);
        a[0] += a[p];
    }
    sort(a, a + m);
    cout << a[m - 1];
    return 0;
}
posted @ 2025-05-10 16:38  Yuhhhhh  阅读(56)  评论(0)    收藏  举报