-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy path11321.cpp
More file actions
43 lines (37 loc) · 731 Bytes
/
11321.cpp
File metadata and controls
43 lines (37 loc) · 731 Bytes
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
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int M;
bool SortFunc(int i, int j)
{
if (i % M != j % M)
return i % M < j % M;
if (i & 1) // i is odd
{
if (j & 1)
return i > j;
return true;
}
if (j & 1)
{
return false;
}
return i < j;
}
int main()
{
int N;
vector<int> numbers(10005);
while (cin >> N >> M, cout << N << ' ' << M << '\n', N)
{
for (int i = 0; i < N; ++i)
{
cin >> numbers[i];
}
sort(numbers.begin(), numbers.begin() + N, SortFunc);
;
for (int i = 0; i < N; ++i)
cout << numbers[i] << '\n';
}
}