Cod sursa(job #2431542)

Utilizator memecoinMeme Coin memecoin Data 20 iunie 2019 00:38:03
Problema Medie Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.78 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;
            }
            m /= 2;
            short dec = (a[i] == m) + (a[j] == m);
            s += f[m] - dec;
        }
    }
    
    fout << s;
    
    return 0;
}