## [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;
}

#### Codeforces Round #471 div.2 ABC题解

2018-03-24 14:16:58

#### Codeforces Round #459 (Div. 2) C. The Monster

2018-01-30 09:48:19

#### Codeforces Round #465 (Div. 2) C. Fifa and Fafa(圆问题，数论)

2018-02-20 16:16:48

#### Codeforces Round #482 (Div. 2)

2018-05-15 12:51:24

#### Codeforces Round #475 (Div. 2) C. Alternating Sum(求逆元)

2018-04-18 09:29:30

#### Codeforces Round #447 (Div. 2) C. Marco and GCD Sequence (构造 贪心)

2017-11-20 13:19:26

#### Codeforces Round #377 (Div. 2)C. Sanatorium(贪心）

2016-10-26 20:08:59

#### Codeforces Round #465 (Div. 2) D. Fafa and Ancient Alphabet

2018-02-20 04:30:43

#### Educational Codeforces Round 38 (Rated for Div. 2) B. Run For Your Prize

2018-02-17 13:35:37

#### Codeforces Round #413 C. Fountains（RMQ线段树）

2017-05-13 09:30:17

## 不良信息举报

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