Submission #355101

#TimeUsernameProblemLanguageResultExecution timeMemory
355101Lam_lai_cuoc_doiSparklers (JOI17_sparklers)C++17
0 / 100
1 ms364 KiB
#include <iostream>
#include <cstdio>
#include <cmath>
#define task ""
using namespace std;
using ll = long long;
using ld = long double;

const int N = 1e5 + 2;
const int Inf = 1e9 + 7;
int n, T, k;
int x[N];

void Read()
{
    cin >> n >> k >> T;
    for (int i = 1; i <= n; ++i)
        cin >> x[i];
}

bool Check(int v)
{
    int a(Inf), b(-Inf);
    if (k > 1 && 2ll * v * T >= (x[k] - x[k - 1]))
    {
        a = k - 1;
        b = k;
    }
    else if (k < n && 2ll * v * T >= (x[k + 1] - x[k]))
    {
        a = k;
        b = k + 1;
    }
    if (a == Inf)
        return false;
    while (a > 1 || b < n)
    {
        bool flag(1);
        if (a > 1 && (2ll * T * v >= (x[b] - x[a - 1]) || 2ll * T * v * (b - a + 1) >= (x[b] - x[a - 1])))
        {
            flag = 0;
            --a;
        }
        else if (b < n && (2ll * T * v >= (x[b + 1] - x[a]) || 2ll * T * v * (b - a + 1) >= (x[b + 1] - x[a])))
        {
            flag = 0;
            ++b;
        }
        if (flag)
            return false;
    }
    return true;
}

void Solve()
{
    int l = 0, m, h = 1e9 + 7;
    while (l <= h)
    {
        m = (l + h) / 2;
        if (!Check(m))
            l = m + 1;
        else
            h = m - 1;
    }
    cout << l;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if (fopen(task ".INP", "r"))
    {
        freopen(task ".INP", "r", stdin);
        freopen(task ".OUT", "w", stdout);
    }
    Read();
    Solve();
}

Compilation message (stderr)

sparklers.cpp: In function 'int32_t main()':
sparklers.cpp:76:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   76 |         freopen(task ".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sparklers.cpp:77:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   77 |         freopen(task ".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...