-
Notifications
You must be signed in to change notification settings - Fork 0
/
ONEKING.cs
63 lines (60 loc) · 2.04 KB
/
ONEKING.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MMT_Elitmus
{
class ONEKING
{
static void Main2(string[] args)
{
int T = Convert.ToInt32(Console.ReadLine());
while (T > 0)
{
int N = Convert.ToInt32(Console.ReadLine());
int c = 0;
List<string> elems = new List<string>();
for (int i = 0; i < N; i++)
{
string[] k = Console.ReadLine().Split(' ');
int f = Convert.ToInt32(k[0]);
int s = Convert.ToInt32(k[1]);
elems.Add(f +" "+ s);
c++;
}
elems = elems.OrderBy(t => Convert.ToInt32(t.Split(' ')[1])).ToList();
int[] ar = new int[c];
int lasti = 0;
int max = -1;
int answer = 0;
for (int i = 0; i < c; i++)
{
if (i == 0)
{
ar[i] = Convert.ToInt32(elems[i].Split(' ')[1]);
}
else
{
if (Convert.ToInt32(elems[i].Split(' ')[0]) <= Convert.ToInt32(elems[lasti].Split(' ')[1]))
{
ar[i] = Convert.ToInt32(elems[lasti].Split(' ')[1]);
}
else
{
lasti = i;
ar[i] = Convert.ToInt32(elems[i].Split(' ')[1]);
}
}
if (ar[i] > max)
{
answer++;
max = ar[i];
}
}
Console.WriteLine(answer);
T--;
}
}
}
}