Cod sursa(job #3168490)

Utilizator XxThornadoxXStoica Teodora XxThornadoxX Data 12 noiembrie 2023 15:58:15
Problema Cuburi2 Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <iostream>
#include <fstream>
#include <algorithm>

using namespace std;

int v[250005];

int main()
{
    int n, m, x, y;

    ifstream f("cuburi2.in");
    ofstream g("cuburi2.out");

    f >> n >> m;

    for(int i = 1; i <= n; i++)
    {
        f >> v[i];
    }

    for(int k = 1; k <= m; k++)
    {
        f >> x >> y;
        int z = distance(v, max_element(v+x, v+y+1)), ans = 0;
        g << z << " ";

        for(int i = x; i <= y; i++)
        {
            if(i != z)
                ans += abs(i-z)*v[i];
        }

        g << ans << "\n";
    }
}