Cod sursa(job #964587)

Utilizator dutzulBodnariuc Dan Alexandru dutzul Data 21 iunie 2013 16:22:40
Problema Oite Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <iostream>
#include <fstream>
#include <map>

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

#define ll long long
#define LE 1066

map<int,int> Hash1,Hash2;
int a[LE],i,j,n,tpos;
ll result;
int S;

int main(){
   f>>n>>S;

   fo(i,1,n) {
       f>>a[i];
       Hash1[a[i]]++;
   }

   for(i=1;i<=n;++i)
     for(j=i+1;j<=n;++j)
      if (a[i]+a[j]<=S)
         Hash2[a[i]+a[j]]++;

  for(i=1;i<=n;++i)
      for(j=i+1;j<=n;++j)
        if (a[i]+a[j]<=S){
          int  rest=S-a[i]-a[j];
          cout<<rest<<"  "<<a[i]<<"  "<<a[j];
          Hash1[a[i]]--;
          Hash1[a[j]]--;


          tpos=Hash2[rest]-Hash1[rest-a[i]]-Hash1[rest-a[j]];
          if (a[i]+a[j]==rest) tpos--;
           cout<<"---->"<<tpos<<'\n';

         ++Hash1[a[i]];
         ++Hash1[a[j]];
          result+=tpos;
        }

    g<<result/6<<'\n';

  f.close();
  g.close();
    return 0;
}