CF141C Queue

#include <algorithm>
#include <iostream>
using namespace std;
struct Man {
    string s;
    int x;
} a[3500];
bool cmp( Man a, Man b ) {
    return a.x < b.x;
}
int ans[3500];
int main() {
    ios::sync_with_stdio( false );
    int n;
    cin >> n;
    for ( int i = 1; i <= n; i++ ) {
        cin >> a[i].s >> a[i].x;
    }
    sort( a + 1, a + n + 1, cmp );
    bool flag = false;
    for ( int i = 1; i <= n; i++ ) {
        flag |= a[i].x >= i;//a[i].x>=i显然不正确
        ans[i] = i - a[i].x;//ans[i]是前面比他矮的人
        for ( int j = 1; j < i; j++ ) {
            if ( ans[j] >= ans[i] ) {
                ans[j]++;
            }
        }
    }
    if ( flag ) {
        cout << -1 << endl;
        return 0;
    }
    for ( int i = 1; i <= n; i++ ) {
        cout << a[i].s << " " << ans[i] << endl;
    }
    return 0;
}
Last modification:September 30th, 2019 at 12:05 pm
如果您觉得我的文章有用,请赏一颗糖糖。

Leave a Comment