Cod sursa(job #2431543)

Utilizator memecoinMeme Coin memecoin Data 20 iunie 2019 00:48:21
Problema Medie Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.81 kb
#include <fstream>
#include <string>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

#ifdef DEBUG
string name = "data";
#else
string name = "medie";
#endif

ifstream fin(name + ".in");
ofstream fout(name + ".out");

int n;
short a[10000];
short f[8000];

int best = 0;

int main() {
    
    fin >> n;
    
    for (int i = 0; i < n; ++i) {
        fin >> a[i];
        f[a[i]]++;
    }
    
    int s = 0;
    
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            short m = a[i] + a[j];
            if (m % 2 == 1) {
                continue;
            }
            if (a[i] == a[j]) {
                s += f[a[i]] - 2;
            } else {
                s += f[m / 2];
            }
        }
    }
    
    fout << s;
    
    return 0;
}