CSES - Datatähti 2025 alku - Results
Submission details
Task:Tikut
Sender:worst
Submission time:2024-11-03 11:06:55 +0200
Language:C++ (C++20)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int sumArr(std::vector<int>)':
input/code.cpp:11:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for (int i = 0; i < arr.size(); i++) {
      |                     ~~^~~~~~~~~~~~
input/code.cpp: In function 'int solve(std::vector<std::vector<int> >, int, int, int)':
input/code.cpp:47:1: warning: no return statement in function returning non-void [-Wreturn-type]
   47 | }
      | ^
input/code.cpp: In function 'int main()':
input/code.cpp:51:14: error: 'INT_MAX' was not declared in this scope
   51 |     int mn = INT_MAX;
      |              ^~~~~~~
input/code.cpp:4:1: note: 'INT_MAX' is defined in header '<climits>'; did you forget to '#include <climits>'?
    3 | #include <iostream>
  +++ |+#include <climits>
    4 | #include <vector>

Code

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#include <bits/ranges_algo.h>

using namespace std;

int sumArr(vector<int> arr) {
    int r = 0;
    for (int i = 0; i < arr.size(); i++) {
        r += arr[i];
    }

    return r;
}

int solve(vector<vector<int>> v, int n, int k, int mn) {
    for (int i = 0; i < k; i++) {
        vector<int> v1 = v[v.size()-1];
        int parent = sumArr(v1);
        int divider = v1.size();

        v.pop_back();

        divider++;

        vector<int> temp(parent % divider, (parent / divider) + 1);

        vector <int> temp2(divider - (parent % divider), (parent / divider));

        if ((parent / divider) < mn) {
            mn = parent / divider;
        }

        for (int u : temp2) {
            temp.push_back(u);
        }

        v.push_back(temp);

        sort(v.begin(), v.end());

        int mx = v[v.size()-1][0];
        cout << mx - mn << " ";
    }
}

int main() {
    int n,k ;
    int mn = INT_MAX;
    cin >> n >> k;

    vector<vector<int>> v;
    for (int i = 0; i < n; i++) {
        vector<int> temp;
        int a;
        cin >> a;
        temp.push_back(a);
        if (temp[0] < mn) {
            mn = temp[0];
        }
        v.push_back(temp);
    }
    sort(v.begin(), v.end());
    solve(v, n, k, mn);

    return 0;
}