Cod sursa(job #1588577)

Utilizator DobosDobos Paul Dobos Data 3 februarie 2016 11:55:31
Problema A+B Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.21 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin ("patrate6.in");
ofstream fout ("patrate6.out");
const int MOD = 73433;
vector < int > G[MOD + 1];
const int BMax = 1e4;
int pos = BMax - 1;
char Buffer[BMax];
unordered_map < int , int > Map;
inline void Read(int &x){
    while(!isdigit(Buffer[pos])){
        if(++pos == BMax){
            fin.read(Buffer, BMax);
            pos = 0;
        }
    }
    x = 0;
    while(isdigit(Buffer[pos])){
        x = x * 10 + (Buffer[pos] - '0');
        if(++pos == BMax){
            fin.read(Buffer, BMax);
            pos = 0;
        }
    }
}

int main()
{
    int n,x,mx;
    Read(n);
    for(int i = 1; i <= n; i++){
        Read(x);
        Map[x]++;
        while(Map[x] == 4){
            Map[x] = 0;
            Map[++x]++;
        }
        if(x > mx)
            mx = x;
    }
    int best = 0;
    int ok = 0;
    for(auto it: Map){
        if(best != it.second && ok == 0) ok = 1;
        if(it.second != 0 && it.first > best)
                best = it.second;
                ok = 1;
        }
    if(k == 1)
        fout << Map.rbegin() -> first;
    else
        fout << Map.rbegin() -> first + 1;
    return 0;
}