Cod sursa(job #2568161)

Utilizator NashikAndrei Feodorov Nashik Data 3 martie 2020 21:11:36
Problema Oite Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.7 kb
//#include <iostream>
#include <fstream>
#include <unordered_map>
#include <random>
#include <iterator>
#include <algorithm>
using namespace std;
unordered_map <long long,int> sum;
long long v[1500],n,l,suma,var;
int main()
{
    ifstream cin("oite.in");
    ofstream cout("oite.out");
    random_device rd;
    mt19937 g(rd());
    cin>>n>>l;
    for(int i=1;i<=n;i++){
        cin>>v[i];
    }
    std::shuffle(v+1,v+n+1, g);
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            if(v[i]+v[j]<=l)
            var+=sum[l-v[i]-v[j]];
        }
        for(int j=i-1;j>=1;j--){
            if(v[i]+v[j]<=l)
             sum[v[i]+v[j]]++;
        }
    }
    cout<<var;
    return 0;
}
//13 1 12 1 12 1