include map include cstdio include iostream include iomanip include st

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <map>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <cstring>
#include <climits>
#include <algorithm>
#include <set>
#include <queue>
#include <ctime>
using namespace std;
#define PATH "D:\\QtProjects\\olymp\\"
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef vector<int> VI;
typedef unsigned int uint;
const int N = 1010;
int m1[N];
int used[N];
bool g2[N][N] = {0};
int curIter = 0;
vector<int> g[N];
inline bool kuhn1(int v){
if (used[v] == curIter) return false;
used[v] = curIter;
for (int to : g[v]){
if (m1[to] == -1 || kuhn1(m1[to])){
m1[to] = v;
return true;
}
}
return false;
}
inline bool kuhn2(int v, int cantfrom, int cantto){
if (used[v] == curIter) return false;
used[v] = curIter;
if (v != cantfrom && g2[v][cantto]) return true;
for (int to : g[v]) if (v != cantfrom || to != cantto){
if (kuhn2(m1[to], cantfrom, cantto)){
return true;
}
}
return false;
}
int sqr[N];
int main(){
ios_base::sync_with_stdio(false);
int n; cin >> n;
clock_t st = clock();
for(int i = 0; i < n; ++i)
cin >> sqr[i];
for(int i = 0; i < n; ++i){
int mn, mx;
cin >> mn >> mx;
for (int j = 0; j < n; ++j){
if (sqr[j] >= mn && sqr[j] <= mx){
g[j].push_back(i);
g2[j][i] = true;
}
}
}
curIter = 1;
fill(m1, m1 + n, -1);
for (int i = 0; i < n; ++i){
++curIter;
if (!kuhn1(i)){
cout << "Let's search for another office." << endl;
return 0;
}
}
for (int i = 0; i < n && (clock() - st) * 100 < 90 * CLOCKS_PER_SEC; ++i){
int cantto = i;
int cantfrom = m1[i];
m1[i] = -1;
++curIter;
if (kuhn2(cantfrom, cantfrom, cantto)){
cout << "Ask Shiftman for help." << endl;
return 0;
}
m1[cantto] = cantfrom;
}
cout << "Perfect!" << endl;
for (int i = 0; i < n; ++i){
cout << m1[i] + 1 << ' ';
}
cout << endl;
return 0;
}