#include
#include
using namespace std;
int main(void)
{
int n, r;
cin >> n >> r;
int a[100] = { 0 };
for (int i = 0; i < n; i++)
cin >> a[i];
int temp = a[0];
sort(a, a + n);
int ch[100] = { 0 }, th[100] = { 0 };
int ch1 = 0, th1 = 0;
int dch = 0, dth = 0;
int flag = 1;
int i;
for (i = 0; i < n; i++)
{
if(ch1 + a[i] - th1 <= r || a[i + 1] > a[i] + ch1)
{
ch1 += a[i];
ch[dch++] = a[i];
}
else
{
th1 += a[i];
th[dth++] = a[i];
}
}
for (i = 0; i < dth; i++)
if (temp == th[i])
flag = 0;
if (flag)
{
for (int i = 0; i < dch; i++)
if (i == 0)
cout << ch[i];
else
cout << ' ' << ch[i];
cout << endl;
for (int i = 0; i < dth; i++)
if (i == 0)
cout << th[i];
else
cout << ' ' << th[i];
}
else
{
for (int i = 0; i < dth; i++)
if (i == 0)
cout << th[i];
else
cout << ' ' << th[i];
cout << endl;
for (int i = 0; i < dch; i++)
if (i == 0)
cout << ch[i];
else
cout << ' ' << ch[i];
}
return 0;
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)