Cod sursa(job #2068791)

Utilizator AlexPop28Pop Alex-Nicolae AlexPop28 Data 18 noiembrie 2017 11:13:27
Problema Secventa 3 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.04 kb
#include <iostream>
#include <fstream>
#include <iomanip>
// (float)((sc[j]-sc[i-1])/(st[j]-st[i-1]))
void citire();
using namespace std;
ifstream f ("secv3.in");
ofstream g ("secv3.out");
int n, U, L,i,j,x;
double sc[30005], st[30005],maxx, rez1,rez2;
int main()
{
    citire();
    maxx = sc[L]/st[L];
    j=1;
    for(i=L+1; i<=n; i++)
    {
        if(i-L==U)
            j++;
        rez1 = (sc[i] - sc[j-1])/(st[i]-st[j-1]);
        rez2 = (sc[i] - sc[i-L])/(st[i]-st[i-L]);
        if(rez1<rez2)
        {
            rez1 = rez2;
            j=i-L+1;
        }
        maxx = max(maxx,rez1);
    }
    g  << 0 << "."<<(int)(maxx*100);
    f.close();
    g.close();
}
void citire()
{
    f >> n >>L >> U;
    for(i=1; i<=n; i++)
        {
            f >> x;
            sc[i] = sc[i-1] + x;
            // sc e un vector de sume partiale pt costuri
        }
    for(i=1; i<=n; i++)
        {
            f >> x;
            st[i] = st[i-1] + x;
            // st e un vector de sume partiale pt timpi
        }
}