Cod sursa(job #2913932)

Utilizator Mihai_999Diaconeasa Mihai Mihai_999 Data 18 iulie 2022 00:19:55
Problema Secventa 3 Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 3.54 kb
#include <bits/stdc++.h>
#define nl '\n'

using namespace std;

ifstream fin("secv3.in");
ofstream fout("secv3.out");

const int nax = 1e4*3+10;
const double epss = 0.001;
int s[nax], t[nax], n, l, u;
double sp[nax];

bool schgh(double val)
{
    for (int i = 1; i <= n; i++)
        sp[i] = (double)sp[i-1] + (double)s[i] - val*(double)t[i];
    deque <int> dq;
    for (int i = 1; i <= n; i++)
    {
        //cout << sp[i] << nl;
        //if (sp[i] - sp[i-l] >= 0)
          //  return 1;
        /*
        if (dq.front() <= i-u && !dq.empty())
        {
            cout << dq.front();
            dq.pop_front();
        }
        */
        while (!dq.empty() && sp[dq.back()] >= sp[i])
        {
            //cout << sp[dq.back()];
            dq.pop_back();
        }
        dq.push_back(i);
        if (i-dq.front()+1 > u)
            dq.pop_front();
        if (sp[i] - sp[dq.front()] >= 0 && i != dq.front() && i-dq.front()+1 >= l)
            return 1;
    }
    return 0;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    fin >> n >> l >> u;
    for (int i = 1; i <= n; i++)
        fin >> s[i];
    for (int i = 1; i <= n; i++)
        fin >> t[i];
    double from = 0.001, to = 1000.0, sol;
    while (to-from >= 0.01)
    {
        double mid = (from+to)/2;
        if (schgh(mid))
        {
            sol = mid;
            from = mid+0.01;
        }
        else
            to = mid-0.01;
        //cout << 1 << nl;
    }
    fout << fixed << setprecision(2) <<  sol;
    return 0;
}

/*
Pre-submit:
Write a few simple test cases, if sample is not enough.
Are time limits close? If so, generate max cases.
Is the memory usage fine?
Could anything overflow?
Make sure to submit the right file.

Wrong answer:
Print your solution! Print debug output, as well.
Are you clearing all datastructures between test cases?
Can your algorithm handle the whole range of input?
Read the full problem statement again.
Do you handle all corner cases correctly?
Have you understood the problem correctly?
Any uninitialized variables?
Any overflows?
Confusing N and M, i and j, etc.?
Are you sure your algorithm works?
What special cases have you not thought of?
Are you sure the STL functions you use work as you think?
Add some assertions, maybe resubmit.
Create some testcases to run your algorithm on.
Go through the algorithm for a simple case.
Go through this list again.
Explain your algorithm to a team mate.
Ask the team mate to look at your code.
Go for a small walk, e.g. to the toilet.
Is your output format correct? (including whitespace)
Rewrite your solution from the start or let a team mate do it.

Runtime error:
Have you tested all corner cases locally?
Any uninitialized variables?
Are you reading or writing outside the range of any vector?
Any assertions that might fail?
Any possible division by 0? (mod 0 for example)
Any possible infinite recursion?
Invalidated pointers or iterators?
Are you using too much memory?
Debug with resubmits (e.g. remapped signals, see Various).

Time limit exceeded:
Do you have any possible infinite loops?
What is the complexity of your algorithm?
Are you copying a lot of unnecessary data? (References)
How big is the input and output? (consider scanf)
Avoid vector, map. (use arrays/unordered_map)
What do your team mates think about your algorithm?

Memory limit exceeded:
What is the max amount of memory your algorithm should need?
Are you clearing all datastructures between test cases?
*/