CSES - Datatähti 2025 alku - Results
Submission details
Task:Tikut
Sender:OorigamiK
Submission time:2024-10-28 20:04:32 +0200
Language:C++ (C++20)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:55:43: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<float>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |                         for (int t = 0; t < splittingSize.size(); t++) {
      |                                         ~~^~~~~~~~~~~~~~~~~~~~~~
input/code.cpp:68:27: warning: overflow in conversion from 'long int' to 'int' changes value from '9999999999' to '1410065407' [-Woverflow]
   68 |                 int min = 9999999999;
      |                           ^~~~~~~~~~
input/code.cpp:69:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<float>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |                 for (int t = 0; t < splittingSize.size(); t++) {
      |                                 ~~^~~~~~~~~~~~~~~~~~~~~~
input/code.cpp:71:35: error: 'ceil' was not declared in this scope
   71 |...

Code

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
	std::vector<int> numbers;
	int n, m;
	int number;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> number;
		numbers.push_back(number);

	}
	sort(numbers.begin(), numbers.end());

	for (int i = 0; i < m; i++) {
		int sum = numbers[n-1];
		int k = n - 2;
		if (!(float(sum) / (i + 2) <= numbers[k] && k >= 0)) {
			//cout << sum << " " << k+1 << " " << i << endl;
		}
		while (float(sum) / (i+(n-k)) <= numbers[k] && k>=0) {
			//cout << sum << " " << k<<" "<<i << endl;
			sum += numbers[k];
			k--;
		}
		float mean = float(sum) / (i + (n - k));
		//cout << "div " << i + (n - k) << endl;
		int numOfSplits = n-1 - k;
		//std::cout << "num of splits " << numOfSplits << endl;
		k++;
		//std::cout << "k " << numbers[k] << endl;
		//std::cout << "mean " << mean << endl;
		std::vector<int> splittingNumbers;
		std::vector<float> splittingSize;
		int sumOfSplittingNums=0;
		for (int j = n - 1; j >= k; j--) {
			//std::cout << "j " << j << endl;
			int splitNum = (numOfSplits) * float(numbers[j]) / sum;
			//cout << "splitNm " << splitNum<<" "<< float(numbers[j]) / (splitNum+1) << endl;
			sumOfSplittingNums += splitNum;
			splittingNumbers.push_back(splitNum);
			if (splitNum != 0) {
				splittingSize.push_back(float(numbers[j]) / (splitNum+1));
			}
		}
		int dif = numOfSplits - sumOfSplittingNums;
		//std::cout << "dif " << dif << endl;
		while (dif > 0) {
			int max=0;
			int index=0;
			for (int t = 0; t < splittingSize.size(); t++) {
				if (max < splittingSize[t]) {
					max = splittingSize[t];
					index = t;
				}
			}
			//std::cout << "index " << index<<" "<<splittingNumbers[index] << " " << n - 1 - index << endl;
			splittingNumbers[index]+=1;
			splittingSize[index] = float(numbers[n-1-index]) / (1+splittingNumbers[index]);
			//std::cout << "splits left "<<dif<<" " << splittingSize[index] << endl;
			dif--;
		}
		int max = 0;
		int min = 9999999999;
		for (int t = 0; t < splittingSize.size(); t++) {
			//std::cout << "splitSize "<<t<<" " << splittingSize[t] << endl;
			if (max < ceil(splittingSize[t])) {
				max = ceil(splittingSize[t]);
			}
			if (min > floor(splittingSize[t])) {
				min = floor(splittingSize[t]);
			}
		}
		for (int t = n-1-splittingSize.size(); t >= 0; t--) {
			if (max < numbers[t]) {
				max = numbers[t];
			}
			if (min > numbers[t]) {
				min = numbers[t];
			}
			//std::cout << "min check " << numbers[t] << " " << min << endl;

		}
		//std::cout << "abs diff " << max - min<<" "<<max<<" "<<min << endl;
		//cout << endl;
		std::cout << max - min << " ";
	}
	return 1;
}