Codeforces Global Round 14 C. Phoenix and Towers(思维)

https://codeforces.com/contest/1515/problem/C

题目大意:

给定一个长度为n的序列a,ai表示方块的高度。每一个方块的高度都在1和q之间。

让我们用这n个方块搭建m座塔,两两之间高度差不能超过q。
input 
2
5 2 3
1 2 3 1 2
4 3 3
1 1 2 3
output 
YES
1 1 1 2 2
YES
1 2 2 3
  • 因为每一个方块的高度范围都在[1,q]之内,每次我得到一个方块的时候把它加入到最低高度的塔中,它的高度对于全体塔高来说,无异于两种情况:
  • 不高于最高的塔,不会超过q的高度差;
  • 高过最高的塔,它变成最高的塔,和此时的最低的塔也不会超过范围。
  • 因此是一定只有YES的情况。
    eg样例一
    1 2 3 1 2
    0 0 1
    0 1 2
    1 2 3
    2 2 3
    2 3 4
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL N=500200,M=2002;
LL a[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T=1;
    cin>>T;
    while(T--)
    {
        LL n,m,q;
        cin>>n>>m>>q;
        cout<<"YES"<<endl;
        set<PII> st;
        for(int i=1;i<=m;i++)//m个独立的塔,每座塔的初始化高度为0
        {
            st.insert({0,i});
        }
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
            PII top=*st.begin();
            st.erase(top);
            cout<<top.second<<" ";//每次插入到最小位置上
            st.insert({top.first+a[i],top.second});
        }
        cout<<endl;
    }
    return 0;
}
posted @ 2022-12-26 20:18  高尔赛凡尔娟  阅读(17)  评论(0编辑  收藏  举报