forked from kothariji/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path026. Unlucky ticket.cpp
71 lines (65 loc) · 1.23 KB
/
026. Unlucky ticket.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <bits/stdc++.h>
#include <cstdlib>
#include <vector>
#include <string>
using namespace std;
void solve()
{
int n = 0;
int i = 0;
vector<int> a, b;
string s;
cin >> n >> s;
for(i = 0; i < n; i++)
{
a.push_back(s[i] - '0');
}
for(i = n; i < 2 * n; i++)
{
b.push_back(s[i] - '0');
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
i = 0;
if(a[0] < b[0])
{
while(i < n && a[i] < b[i])
i++;
if(i < n)
{
cout << "NO" << endl;
return;
}
else
{
cout << "YES" << endl;
return;
}
}
else if(a[0] > b[0])
{
while(i < n && a[i] > b[i])
i++;
if(i < n)
{
cout << "NO" << endl;
return;
}
else
{
cout << "YES" << endl;
return;
}
}
else if(a[0] == b[0])
cout << "NO" << endl;
}
int main()
{
//for fast input output
ios_base::sync_with_stdio(false);cin.tie(NULL);
solve();
//to show actual running time of program
cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
return EXIT_SUCCESS;
}