Submission #1330621

#TimeUsernameProblemLanguageResultExecution timeMemory
1330621bradley0927Room Temperature (JOI24_ho_t1)C++20
Compilation error
0 ms0 KiB
#include <iostream>
#include <vector>
using namespace std;
int n, t;
vector<int> v;

int max_discomfort(int x) {
    int max_d = 0;
    for (int i = 0; i < v.size(); i++) {
        int k = max(0, (v[i] - x)/t);//optimal jacket count
        int temp = v[i] - k*t;
        max_d = max(max_d, abs(x - temp));
    }
    return max_d;
}

int main() {
    //ans = sum of modulo?
    int mx = 0, mn = INT_MAX;
    cin >> n >> t;
    v.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        mx = max(mx, v[i]);
        mn = min(mn, v[i]);
    }
    //ternery search
    int l = mn, r = mx;
    while (r - l > 2) {
        int m1 = l + (r - l)/3;
        int m2 = r - (r - l)/3;
        if (max_discomfort(m1) < max_discomfort(m2)) r = m2;
        else l = m1;
    }
    int ans = INT_MAX;
    for (int i = l; i <= r; i++) ans = min(ans, max_discomfort(i));
    cout << ans << endl;
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:19:22: error: 'INT_MAX' was not declared in this scope
   19 |     int mx = 0, mn = INT_MAX;
      |                      ^~~~~~~
Main.cpp:3:1: note: 'INT_MAX' is defined in header '<climits>'; did you forget to '#include <climits>'?
    2 | #include <vector>
  +++ |+#include <climits>
    3 | using namespace std;