Cod sursa(job #2408665)

Utilizator tifui.alexandruTifui Ioan Alexandru tifui.alexandru Data 18 aprilie 2019 11:02:05
Problema Oite Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <bits/stdc++.h>
#define MAXN 1030

using namespace std;

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

int v[MAXN];
unordered_map <int,int> HM;
int N,G,ans;

void read_data(){

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

void solve(){

    for(int j,i=1;i<=N;i++){

        for(j=i+1;j<=N;j++)
            if(v[i]+v[j]<=G)
                ans+=HM[G-v[i]-v[j]];
        for(j=i-1;j;j--)
            if(v[i]+v[j]<=G)
                ++HM[v[i]+v[j]];
    }
    g<<ans;
}

int main(){

    read_data();
    solve();

    return 0;
}