Cod sursa(job #2656395)

Utilizator PatrickCplusplusPatrick Kristian Ondreovici PatrickCplusplus Data 7 octombrie 2020 17:09:32
Problema Progresii Scor 10
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;
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;
        if (b == 0){
            x = a + 1;
        }
        else{
            x = max(1LL, a / b + (a % b != 0 ? 1 : 0));
        }
        cost = 1LL * cost + 1 + 1LL * (l - v[i]) / x;
        fout << x << "\n";
    }
    fin.close();
    fout.close();
    return 0;
}