Cod sursa(job #2656412)

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

using namespace std;

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

const int nmax = 100005;
int n;
long long m, k, l, v[nmax], cost;

int main(){
    fin >> n >> m >> k >> l;
    for (int i = 1; i <= n; ++i){
        fin >> v[i];
        cost = 1LL * cost + 1 + 1LL * (l - v[i]) / m;
        if (cost > k){
            fout << -1;
            return 0;
        }
    }
    for (int i = 1; i <= n; ++i){
        cost = 1LL * cost - (1 + 1LL * (l - v[i]) / m);
        long long b = k - cost - 1;
        long long a = l - v[i];
        long long x = m;
        if (b == 0){
            x = a + 1;
        }
        else{
            x = a / b;
            if (1LL * cost + 1 + 1LL * (l - v[i]) / x > k){
                x = x + 1;
            }
            else if (x - 1 > 0 && 1LL * cost + 1 + 1LL * (l - v[i]) / (x - 1) <= k){
                x = x - 1;
            }
        }
        cost = 1LL * cost + 1 + 1LL * (l - v[i]) / x;
        fout << x << "\n";
    }
    fin.close();
    fout.close();
    return 0;
}