Cod sursa(job #1851641)

Utilizator iordache.bogdanIordache Ioan-Bogdan iordache.bogdan Data 19 ianuarie 2017 22:19:20
Problema Progresii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.44 kb
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm>

const int kDimMax = 100005;

long long contestantCount, maxVelocity, totalSecondCount, length;
long long position[kDimMax];
long long sumIfMaxVelocity[kDimMax]; //total seconds if i..contestantCount has maxVelocity
long long solution[kDimMax];

int main() {
	std::ifstream inputFile("progresii.in");
	std::ofstream outputFile("progresii.out");

	inputFile >> contestantCount >> maxVelocity >> totalSecondCount >> length;
	totalSecondCount -= contestantCount;

	for (int i = 1; i <= contestantCount; ++i)
		inputFile >> position[i];

	for (int i = contestantCount; i; --i)
		sumIfMaxVelocity[i] = sumIfMaxVelocity[i + 1] + (length - position[i]) / maxVelocity;

	if (sumIfMaxVelocity[1] > totalSecondCount) {
		outputFile << "-1\n";
		return 0;
	}

	for (int i = 1; i <= contestantCount; ++i) {
		//try to make i as slow as possible
		long long maxSecondCountForI = totalSecondCount - sumIfMaxVelocity[i + 1] + 1;

		if (maxSecondCountForI == 0)
			solution[i] = length - position[i] + 1;
		else
			solution[i] = (length - position[i]) / maxSecondCountForI + 1;

		if (solution[i] == 0)
			solution[i] = 1;

		totalSecondCount -= (length - position[i]) / solution[i];
	}

	for (int i = 1; i <= contestantCount; ++i)
		outputFile << solution[i] << '\n';

	inputFile.close();
	outputFile.close();

	return 0;
}

//Trust me, I'm the Doctor!