Submission #713002

# Submission time Handle Problem Language Result Execution time Memory
713002 2023-03-20T19:09:39 Z tamyte Swimming competition (LMIO18_plaukimo_varzybos) C++14
0 / 100
1 ms 320 KB
#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) {
    // cout << max_diff << "\n";
    for (int i = 0; i < arr.size() - left; ++i) {
        if (arr[i + left - 1] - arr[i] > max_diff) return false;
        int j = left + i;
        for (; j < min(right + i, (int)arr.size()); ++j) {
            if (arr[j] - arr[i] > max_diff) {
                break;
            }
        }
        i = j - 1;
    }
    return true;
}



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 + 1;
}

Compilation message

plaukimo_varzybos.cpp: In function 'bool ok(int, std::vector<int>&, int, int)':
plaukimo_varzybos.cpp:21:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for (int i = 0; i < arr.size() - left; ++i) {
      |                     ~~^~~~~~~~~~~~~~~~~~~
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 time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -