Pagini recente » Cod sursa (job #2452291) | Cod sursa (job #2145370) | Cod sursa (job #1996166) | Cod sursa (job #350114) | Cod sursa (job #2751806)
#include <iostream>
#include <cctype>
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
const int BUFSIZE = 1 << 16, INF = (1 << 30) - 1 + (1 << 30);
char rBuf[BUFSIZE], wBuf[BUFSIZE];
int wPos, rPos;
int Pow10[11] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, INF}; ///intrebare legata de asta: dc nu merge sa pun in vector 1e2
FILE *fin, *fout;
inline void initRBuf();
inline void initWBuf();
inline char getChar();
inline void putChar(char ch);
inline void flushWBuf();
inline int getInt();
inline void writeInt(int nr);
struct cmp
{
public : bool operator()(const int a, const int b) const
{
return (a > b);
}
};
priority_queue<int, vector<int>, cmp> myHeap;
int main()
{
fin = fopen("interclasari.in", "r");
initRBuf();
initWBuf();
int k, n, i, j, s = 0;
k = getInt();
for (i = 0; i < k; i++)
{
n = getInt();
s += n;
for (j = 0; j < n; j++)
myHeap.push(getInt());
}
fclose(fin);
fout = fopen("interclasari.out", "w");
writeInt(s);
putChar('\n');
while (!myHeap.empty())
{
writeInt(myHeap.top());
putChar(' ');
myHeap.pop();
}
flushWBuf();
fclose(fout);
return 0;
}
inline void initRBuf() { rPos = BUFSIZE - 1; }
inline void initWBuf() { wPos = -1; }
inline char getChar()
{
if (++rPos == BUFSIZE)
{
rPos = 0;
fread(rBuf, 1, BUFSIZE, fin);
}
return rBuf[rPos];
}
inline void putChar(char ch)
{
if (++wPos == BUFSIZE)
{
wPos = 0;
fwrite(wBuf, 1, BUFSIZE, fout);
}
wBuf[wPos] = ch;
}
inline void flushWBuf() { fwrite(wBuf, 1, wPos + 1, fout); }
inline int getInt()
{
char ch;
int res = 0;
while (!isdigit(ch = getChar()));
do
res = res * 10 + ch - '0';
while (isdigit(ch = getChar()));
return res;
}
inline void writeInt(int nr)
{
int i = 1, cf;
while (Pow10[i] <= nr)
i++;
i--;
for (; i >= 0; i--)
{
cf = 0;
while (nr >= Pow10[i])
{
cf++;
nr -= Pow10[i];
}
putChar(cf + '0');
}
}