Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- #include <queue>
- #define INF 100000000
- using namespace std;
- int a[100][100], c[10001];
- struct Coord
- {
- int x, y, cost;
- bool operator < (const Coord &v) const
- {
- return a[x][y] > a[v.x][v.y];
- }
- };
- priority_queue <Coord> q;
- int main()
- {
- int i, j, x, p;
- Coord v;
- int n, k;
- ifstream fin("date.in");
- fin >> k >> n;
- for(i = 1; i <= k; i++)
- for(j = 1; j <= n; j++)
- fin >> a[i][j];
- /// pun infnit pe ultima coloana
- for(i = 1; i <= k; i++)
- a[i][n + 1] = INF;
- /// pun prima coloana in q
- for(i = 1; i <= k; i++)
- {
- v.x = i;
- v.y = 1;
- q.push(v);
- }
- /// interclasarea
- x = n * k;
- for(p = 1; p <= x; p++)
- {
- v = q.top();
- q.pop();
- c[p] = a[v.x][v.y];
- v.y++;
- q.push(v);
- }
- for(p = 1; p <= x; p++)
- cout << c[p] << " ";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment