Cod sursa(job #1709844)

Utilizator pyfloriUsurelu Florian pyflori Data 28 mai 2016 14:09:25
Problema Tribut Scor 0
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 0.51 kb
#include <fstream>

using namespace std;
ifstream f ("pq.in");
ofstream g ("pq.out");
int x,y,i,j,l,n,q,v[100001],co,cost,t;
int main()
{
    f>>n>>q;
    for(i=1;i<=n;++i) f>>v[i];
    for(j=1;j<=q;++j)
    {
        f>>x>>y;
        cost=0;
        for(i=x;i<y;++i)
        {
            for(t=i+1;t<=y;++t)
            {
                if(v[i]==v[t]) {co=t-i; if(co>cost) cost=co; break;}
            }
        }
        if(!cost) g<<-1<<"\n";
        else g<<cost<<"\n";
    }
    return 0;
}