Cod sursa(job #2673292)

Utilizator PredescuSebastianIonPredescu Sebastian Ion PredescuSebastianIon Data 16 noiembrie 2020 14:14:56
Problema Oite Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <fstream>
#include <algorithm>
#include <unordered_map>

using namespace std;
ifstream f("oite.in");
ofstream g("oite.out");
int l,n,sol,a[1025];
unordered_map <int, int> mp;
int main()
{
    f>>n>>l;
    for(int i=1;i<=n;i++)
    {
        f>>a[i];
    }
    sort(a+1,a+n+1);
    for(int i=1;i<n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            int s=a[i]+a[j];
            if(mp[l-s]>0)
            {
                sol+=mp[l-s];
            }
        }
        for(int j=i-1;j>=1;j--)
        {
            mp[a[i]+a[j]]++;
        }
    }
    g<<sol<<'\n';
    return 0;
}