-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathURI1462_TL.cpp
51 lines (47 loc) · 927 Bytes
/
URI1462_TL.cpp
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
#include <bits/stdc++.h>
using namespace std;
bool desc(int i, int j) { return (i > j); }
int main(){
int N;
while (scanf("%d", &N) != EOF){
vector<int> vec;
for (int i = 0; i < N; i++){
int x;
cin >> x;
vec.push_back(x);
}
sort(vec.begin(), vec.end(), desc);
vec.push_back(-1);
bool possivel = true;
for (int i = 0; i < N; i++){
if (possivel){
int x = vec[i];
int j = i;
while (x > 0){
if (vec[j + 1] > 0){
vec[j + 1] = vec[j + 1] - 1;
x--;
j++;
}
else if (vec[j + 1] == 0){
j++;
}
else if (vec[j + 1] < 0){
possivel = false;
break;
}
}
}
else{
break;
}
}
if (possivel){
cout << "possivel\n";
}
else{
cout << "impossivel\n";
}
}
return 0;
}