Cod sursa(job #2568250)

Utilizator ancaoxoxSfia Anca ancaoxox Data 3 martie 2020 21:40:02
Problema Oite Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.25 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <unordered_map>
#include <random>
#include <iterator>
#include <algorithm>
using namespace std;
unordered_map <int,int> sum;
int v[1050],n,l,suma,var;
vector<pair<int,int> > gaina[69696969];
int gas(int a){
    int aa=a;
    a%=1000007;
    for(auto u:gaina[a]){
        if(u.first==aa)
            return u.second;
    }
    return 0;
}

//feo e trist
// feo e trist
// feo e trist
// feo e trist
// feo e trist
// feo e trist

void ins(int a){
    int aa=a;
    a%=1000007;
    for(auto u:gaina[a]){
        if(u.first==aa){
            u.second++;
            return;
        }
    }
    gaina[a].push_back(make_pair(a,1));
}
int main()
{
    //ofstream cout("oite.out");
    cin>>n>>l;
    for(int i=1;i<=n;i++){
        cin>>v[i];
    }
    sort(v+1,v+n+1);
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            if(v[i]+v[j]<=l){
                var+=gas(l-v[i]-v[j]);
            }
            else
                break;
        }
        for(int j=1;j<i;j++){
            if(v[i]+v[j]<=l){
                ins(v[i]+v[j]);
            }
            else
                break;
        }
    }
    cout<<var;
    return 0;
}