Cod sursa(job #1795972)

Utilizator mihai.alphamihai craciun mihai.alpha Data 2 noiembrie 2016 23:19:56
Problema Interclasari Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.15 kb
#include <bits/stdc++.h>
using namespace std;
#define BUF_SIZE 1<<17
char buf[BUF_SIZE];
int pos = BUF_SIZE;
FILE *fin, *fout;
inline char nextch(){
    if(pos==BUF_SIZE) fread(buf, BUF_SIZE, 1, fin), pos=0;
    return buf[pos++];
}

inline int read(int &x){
    x = 0;
    char ch=nextch();
    while(!isdigit(ch)) ch=nextch();
    while(isdigit(ch)){
        x=10*x+ch-'0';
        ch=nextch();
    }
    return x;
}
#define MAXN 2000010
int v[MAXN];
struct comparator{
    bool operator()(int i,int j){
        return i < j;
    }
};
multiset <int, comparator> heap;
int main()  {
fin = fopen("interclasari.in", "r");
fout = fopen("interclasari.out", "w");
int n, k, i, nr;
read(k);n = 0;
for(i = 0;i < k;i++)  {
    read(nr);
    for(int j = 0;j < nr;j++)  {
        ++n;
        read(v[j]);
      //  printf("%d %d\n", v[j], j);
        heap.insert(v[j]);
    }
}
fprintf(fout, "%d\n", n);
int curr;

for(i = 0;i < n;i++)  {
    curr=*heap.begin();
      for (std::multiset<int>::iterator it=heap.begin(); it != heap.end(); ++it)  {
      if(*it != *heap.begin())
      break;
    fprintf(fout,"%d ", *it);
    }
    heap.erase(curr);

}
fclose(fin);
fclose(fout);
return 0;
}