Cod sursa(job #2326994)

Utilizator ApostolIlieDanielApostol Daniel ApostolIlieDaniel Data 24 ianuarie 2019 12:20:18
Problema Oite Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <bits/stdc++.h>

using namespace std;

const int MAX = 1e6;

#define ll long long
#define unu first
#define doi second

vector < pair <int, int> > v[MAX];

void add (int x) {
  for (auto &y : v[x % MAX]) {
    if (y.unu == x) {
      y.doi++;
      return;
    }
  }
  v[x % MAX].push_back ({x, 1});
}

int find (int x) {
  for (auto y : v[x % MAX])
    if (y.unu == x)
      return y.doi;
  return 0;
}

const int MAXN = 1024;

int a[MAXN + 1];
int main() {

  int n, l, i, sol, j;

  freopen ("oite.in", "r", stdin);
  freopen ("oite.out", "w", stdout);

  scanf ("%d%d", &n, &l);

  for (i = 1; i <= n; i++)
    scanf ("%d", &a[i]);

  sol = 0;

  for (i = 2; i <= n; i++) {
    for (j = i + 1; j <= n; j++)
      if (a[i] + a[j] <= l) {
        sol = sol + find (l - a[i] - a[j]);
      }
    for (j = i - 1; j > 0; j--)
      add (a[i] + a[j]);
  }

  printf ("%d", sol);

  return 0;
}