Cod sursa(job #2415876)

Utilizator AndreiStrAndrei Stroici AndreiStr Data 26 aprilie 2019 16:18:47
Problema Secventa 2 Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.98 kb
#include <bits/stdc++.h>

using namespace std;
ifstream f("secv2.in");
ofstream g("secv2.out");
int n,k,a[50001],s[50001],x,y,z,q,sol=-25001;

int main()
{
    f>>n>>k;
    for(int i=1; i<=n; i++)
    {
        f>>a[i];
        s[i]=a[i];
    }
    sort(a+1,a+n+1);
    int j=n;
    while(j!=n-k)
    {
        z+=a[j];
        j--;
    }
    for(int i=1; i<=n; i++)
        for(int j=n; j>n-k; j--)
            if(s[i]==a[j])
            {
                x=i;
                continue;
            }
    for(int i=n; i>0; i--)
        for(int j=n; j>n-k; j--)
            if(s[i]==a[j])
            {
                y=i;
                continue;
            }
    if(a[y-1]>0)
    {
        y++;
        while(a[y]>0)
        {
            z+=a[y];
            y--;
        }
    }
    if(a[x+1]>0)
    {
        x++;
        while(a[x]>0)
        {
            z+=a[x];
            x++;
        }
    }
    g<<y<<' '<<x<<' '<<z;
    return 0;
}