-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1252.cpp
More file actions
35 lines (26 loc) · 742 Bytes
/
1252.cpp
File metadata and controls
35 lines (26 loc) · 742 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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll m;
bool ordena(ll a, ll b) {
if(a % m == b % m){
if(abs(a % 2) == 0 && abs(b % 2) == 0) return a < b;
if(abs(a % 2) == 1 && abs(b % 2) == 1) return a > b;
if(abs(a % 2) == 0 && abs(b % 2) == 1) return false;
if(abs(a % 2) == 1 && abs(b % 2) == 0) return true;
}
return (a % m) < (b % m);
}
int main(){
ll n;
while(true){
cin >> n >> m;
cout << n << " " << m << endl;
if(n == 0 && m == 0) break;
vector<ll> v(n);
for(ll i = 0; i < n; i++) cin >> v[i];
sort(v.begin(), v.end(), ordena);
for(ll i = 0; i < n; i++) cout << v[i] << endl;
}
return 0;
}