P6389 题解

· · 题解

题面描述

题目已经说过:

但为了整体的和谐,不能有两个以上的乐师在同一个时刻休息

所以前两个乐师分别从时刻 0 开始休息,满足题目要求。

题目思路

接下来的乐师只需要等前面的任意一名乐师休息完后立刻开始休息。

因此我们可以用两个计数器判断两处的乐师休息时间总和,

并让新乐师选择 时间少 的一边加入。

Code

#include <bits/stdc++.h>
using namespace std;
int t,n,work,rest;//两处休息点
int main(){
cin.tie(NULL);cout.tie(NULL);//没有什么用的优化
    cin >> t >> n;
    while(n--){
    int a;
    cin >> a;
    if(work<rest){
    cout << work << " ";
    work+=a;
}else{
cout << rest << " ";
rest+=a;
    }
    }
    return 0;
}