Cod sursa(job #2656278)

Utilizator PatrickCplusplusPatrick Kristian Ondreovici PatrickCplusplus Data 7 octombrie 2020 13:06:50
Problema Progresii Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.88 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("progresii.in");
ofstream fout("progresii.out");

const int nmax = 100005;
int n, m, k, l, v[nmax], cost;
int main(){
    fin >> n >> m >> k >> l;
    for (int i = 1; i <= n; ++i){
        fin >> v[i];
        cost += 1 + (l - v[i]) / m;
    }
    if (cost > l){
        fout << -1 << "\n";
        return 0;
    }
    for (int i = 1; i <= n; ++i){
        int st = 1, dr = m, ans = m;
        cost -= 1 + (l - v[i]) / m;
        while (st <= dr){
            int mid = (st + dr) / 2;
            if (cost + 1 + (l - v[i]) / mid <= k){
                ans = mid;
                dr = mid - 1;
            }
            else{
                st = mid + 1;
            }
        }
        fout << ans << "\n";
        cost += 1 + (l - v[i]) / ans;
    }
    fin.close();
    fout.close();
    return 0;
}