Pagini recente » Cod sursa (job #645395) | Cod sursa (job #3210275) | Cod sursa (job #645389) | Cod sursa (job #2096926) | Cod sursa (job #3140104)
#include <fstream>
#include <algorithm>
#include <bitset>
#include <vector>
using namespace std;
string file = "ghiozdan";
ifstream cin (file + ".in");
ofstream cout (file + ".out");
struct ura{
int x, nr;
};
vector <ura> v[75001];
vector <int> available;
int obiecte[201];
bitset <75001> exista;
int main()
{
int n,g,x;
cin >> n >> g;
for (int i=1; i<=n; i++)
{
cin >> x;
obiecte[x]++;
}
for (int i=200; i>=1; i--)
{
while (obiecte[i]--)
{
vector <int> temp;
x = i;
for (int greutate : available)
{
if (greutate+x > g)
continue;
if (!exista[greutate + x])
{
temp.push_back(greutate+x);
exista[greutate+x] = 1;
v[greutate+x] = v[greutate];
if (v[greutate+x].back().x == x)
{
v[greutate+x].back().nr++;
}
else
{
v[greutate+x].push_back({x,1});
}
}
else if (v[greutate].size() + 1 < v[greutate+x].size())
{
v[greutate+x] = v[greutate];
if (v[greutate+x].back().x == x)
{
v[greutate+x].back().nr++;
}
else
{
v[greutate+x].push_back({x,1});
}
}
}
v[x] = {{x,1}};
if (!exista[x])
{
exista[x] = 1;
temp.push_back(x);
}
for (int x : temp)
{
available.push_back(x);
}
}
}
for (int i=g; i>=1; i--)
{
if (v[i].size())
{
cout << i << ' ' << v[i].size();
for (ura x : v[i])
{
while (x.nr--)
{
cout << '\n' << x.x;
}
}
break;
}
}
}