include[HTML_REMOVED]
include[HTML_REMOVED]
include[HTML_REMOVED]
using namespace std;
const int N = 1010;
int n, m;
struct list
{
string name;
int score;
bool operator< (const list& x)const
{
return score< x.score;
}
bool operator> (const list& x)const
{
return score> x.score;
}
}q[N];
int main()
{
cin >> n >> m;
for(int i = 0; i < n; i++)
cin >> q[i].name >> q[i].score;
//法一 stable_sort()
/*
if(m)
stable_sort(q, q + n);
else
stable_sort(q, q + n, greater<list>());
*/
//法二 冒泡
if(m)
{
for(int i = n - 1; i >= 0; i --)
for(int j = 0; j < i; j ++)
if(q[j].score > q[j + 1].score)
swap(q[j], q[j + 1]);
}
else
{
for(int i = n - 1; i >= 0; i --)
for(int j = 0; j < i; j ++)
if(q[j].score < q[j + 1].score)
swap(q[j], q[j + 1]);
}
//
for(int i = 0; i < n; i ++)
cout << q[i].name << " " << q[i].score << endl;
return 0;
}