-
Notifications
You must be signed in to change notification settings - Fork 0
/
11321
55 lines (47 loc) · 921 Bytes
/
11321
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
#include <iostream>
#include <map>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <vector>
#define ll long long
using namespace std;
pair<int,int> p;
map<long long,bool> m;
queue<long long> q;
vector< pair<int,int> > v;
bool cmp(pair<int,int> a, pair<int,int> b){
if(a.second==b.second){
if(a.first%2==0 && b.first%2==0) return a.first<b.first;
if(a.first%2!=0 && b.first%2!=0) return a.first>b.first;
else {
return a.first%2 > b.first%2;
}
}
else{
return a.second<b.second;
}
}
int main(){
freopen("i.txt","r",stdin);
freopen("o.txt","w",stdout);
int n,m;
int a;
while(cin >> n>> m){
if(!n&& !m) {
cout << "0 0";
break;
}
for(int i=1;i<=n;i++){
cin >> a;
v.push_back(make_pair(a,a%m));
}
// sort
sort(v.begin(),v.end(),cmp);
// cout
cout << n << " " <<m << endl;
for(int i=0;i<v.size();i++){
cout << v[i].first << endl;
}
}
}