# [Codeforces Round #101 (Div. 2) C. Queue] STL之vector

523人阅读 评论(0)

## [Codeforces Round #101 (Div. 2) C. Queue] STL之vector

Let’s sort the pairs (namei, ai) by ascending of ai. If there is an index i: 0 ≤ i < n that ai > i, then answer is “-1”. Otherwise the answer exists. We will iterate through the array of sorted pairs from left to right with supporting of vector of results res. Let on the current iteration ai = n - i, then we must transfer the current man in the position ai. It can be done in C++ with one line: res.insert(res.begin() + a[i], man);

#include <bits/stdc++.h>
using namespace std;

#define FIN             freopen("input.txt","r",stdin)
#define FOUT            freopen("output.txt","w",stdout)
#define fst             first
#define snd             second

typedef __int64 LL;
//typedef long long LL;
typedef pair<int, int> PII;

const int MAXN = 3000 + 5;

int N, M, K;
char buf[MAXN][15];
PII ele[MAXN];
vector<PII> res;

int main() {
#ifndef ONLINE_JUDGE
FIN;
#endif // ONLINE_JUDGE
while (~scanf ("%d", &N) ) {
for (int i = 1; i <= N; i++) {
scanf ("%s %d", buf[i], &ele[i].fst);
ele[i].snd = i;
}
sort (ele + 1, ele + N + 1);
bool suc = true;
for (int i = 1; i <= N; i++) {
if (ele[i].fst >= i) suc = false;
}
if (!suc) {
printf ("-1\n");
continue;
}
res.clear();
for (int i = 1, k = N; i <= N; i++, k--) {
res.insert (res.begin() + ele[i].fst, make_pair (ele[i].snd, k) );
}
for (int i = 0; i < N; i++) {
PII& e = res[i];
printf ("%s %d\n",  buf[e.fst], e.snd);
}
}
return 0;
}
0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：294447次
• 积分：5761
• 等级：
• 排名：第5243名
• 原创：273篇
• 转载：8篇
• 译文：0篇
• 评论：44条
友情链接
最新评论