Submission #713007

#TimeUsernameProblemLanguageResultExecution timeMemory
713007tamyteSwimming competition (LMIO18_plaukimo_varzybos)C++14
100 / 100
429 ms13020 KiB
#include <bits/stdc++.h>


using namespace std;
#define sz(x) (int)(x).size()
void setIO(string name = "")
{
    cin.tie(0)->sync_with_stdio(0); // see /general/fast-io
    if (sz(name))
    {
        freopen((name + ".in").c_str(), "r", stdin); // see /general/input-output
        freopen((name + ".out").c_str(), "w", stdout);
    }
}

/*----------------------------------*/


bool ok(int max_diff, vector<int>& arr, int left, int right) {
    queue<int> q;
    q.push(-1);
    int i = left - 1;
    while (i < arr.size() && q.size()) {
        if (i - q.front() >= left) {
            if (i - q.front() <= right && arr[i] - arr[q.front() + 1] <= max_diff) {
                q.push(i);
                i++;
            } else {
                q.pop();
            }
        } else {
            i++;
        }
    }
    return (q.size() && q.back() == arr.size() - 1);
}



int main()
{
    setIO("");
    int n, a, b;
    cin >> n >> a >> b;
    vector<int> arr(n);
    for (auto& x : arr) cin >> x;
    sort(arr.begin(), arr.end());
    int l = 0, r = *max_element(arr.begin(), arr.end());
    while (l < r) {
        int m = (l + r) / 2;
        if (ok(m, arr, a, b)) r = m;
        else l = m + 1;
    }
    cout << l;
}

Compilation message (stderr)

plaukimo_varzybos.cpp: In function 'bool ok(int, std::vector<int>&, int, int)':
plaukimo_varzybos.cpp:23:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     while (i < arr.size() && q.size()) {
      |            ~~^~~~~~~~~~~~
plaukimo_varzybos.cpp:35:34: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     return (q.size() && q.back() == arr.size() - 1);
      |                         ~~~~~~~~~^~~~~~~~~~~~~~~~~
plaukimo_varzybos.cpp: In function 'void setIO(std::string)':
plaukimo_varzybos.cpp:11:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |         freopen((name + ".in").c_str(), "r", stdin); // see /general/input-output
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
plaukimo_varzybos.cpp:12:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |         freopen((name + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...