Pagini recente » Cod sursa (job #2588954) | Cod sursa (job #2463202) | Cod sursa (job #1632660) | Cod sursa (job #2605978) | Cod sursa (job #1976832)
#include <fstream>
#include <deque>
#include <algorithm>
using namespace std;
ifstream fin("roboti3.in");
ofstream fout("roboti3.out");
const int NMax = 100005;
int V,N;
int A[NMax];
deque <int> DQ;
void Read()
{
fin >> V >> N;
for(int i = 1 ; i <= N ; ++i)
fin >> A[i];
}
int main()
{
Read();
if(V == 1)
{
int Best = 0,Max = 0,Sol = 0;
for(int i = 1 ; i <= N ; ++i)
{
if(A[i] > Max) Best++;
else
{
Sol = max(Sol,Best);
Best = 1;
}
Max = A[i];
}
for(int i = 1 ; i <= N ; ++i)
{
if(A[i] > Max) Best++;
else
{
Sol = max(Sol,Best);
Best = 1;
}
Max = A[i];
}
fout << Sol << "\n";
}
else
{
sort(A + 1 , A + N + 1);
DQ.push_back(A[N]);
for(int i = N - 1 ; i >= 1 ; --i)
{
if(A[i] * DQ.front() >= A[i] * DQ.back())
DQ.push_front(A[i]);
else DQ.push_back(A[i]);
}
while(DQ.front() >= DQ.back())
{
DQ.push_front(DQ.back());
DQ.pop_back();
}
while(!DQ.empty())
{
fout << DQ.front() << " ";
DQ.pop_front();
}
fout << "\n";
}
fin.close();
fout.close();
return 0;
}