CSES - Datatähti 2025 alku - Results
Submission details
Task:Tikut
Sender:worst
Submission time:2024-10-31 10:15:32 +0200
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:9:14: error: 'INT_MAX' was not declared in this scope
    9 |     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 <set>
  +++ |+#include <climits>
    4 | using namespace std;

Code

#include <iostream>
#include <vector>
#include <set>
using namespace std;


int main() {
    int n, m;
    int mn = INT_MAX;
    int mx = 0;
    // Input 2 numbers
    cin >> n >> m;
    // Create a multiset called mlt
    multiset<vector<int> > mlt;

    // Create an integer list
    vector<int> v(n);

    // Input list
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        mlt.insert({v[i], v[i]}); // Current number, parent
        if (v[i] > mx) {
            mx = v[i];
        }
        if (v[i] < mn) {
            mn = v[i];
        }
    }


    for (int i = 0; i < m; i++) {
        auto last = *(--mlt.end());

        // Set parent and divider
        int parent = last.back();
        int divider = last.size() - 1;

        // Delete
        mlt.erase(--mlt.end());

        // Insert
        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);
        }

        temp.push_back(parent);

        mlt.insert(temp);

        // Get the difference between max and min
        auto first = *mlt.begin();
        last = *(--mlt.end());
        mx = last[0];


        int diff = mx - mn;

        // Print difference
        cout << diff << ' ';
    }

    return 0;
}