Pagini recente » Istoria paginii utilizator/o530_citaro | Clasament preONI 2006, Clasele XI-XII | Cod sursa (job #2016651) | Profil Mazzele | Cod sursa (job #581683)
Cod sursa(job #581683)
#include <fstream>
using namespace std;
int n, m, k, l;
int d[100002], v[100002];
int tot;
int main()
{
ifstream fin("progresii.in");
ofstream fout("progresii.out");
fin >> n >> m >> k >> l;
for (int i = 1; i <= n; ++i)
{
fin >> d[i];
d[i] *= -1, d[i] += l;
tot += d[i] + 1;
v[i] = 1;
}
int step;
for (step = 1; (step << 1) <= m; step <<= 1);
for (int i = n; i >= 1 && tot > k; --i)
{
int stepx = step, res, hnow = d[i];
for (res = 0; stepx; stepx >>= 1)
if (res + stepx >= 1 && tot - d[i] + (d[i] / (res + stepx)) >= 0 && (res + stepx == 1 || d[i] / (res + stepx) != d[i] / (res + stepx - 1)))
res += stepx;
tot -= d[i];
tot += (d[i] / (res - stepx));
v[i] = res;
}
if (tot > k) fout << -1 << '\n';
else
for (int i = 1; i <= n; ++i)
fout << v[i] << '\n';
fin.close();
fout.close();
}