Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # include <iostream>
- # include <algorithm>
- using namespace std;
- struct pole
- {
- int first;
- int last;
- int index;
- };
- //int out[10000];
- //pole column[10000];
- bool fun ( pole p1, pole p2 ) { return ( p1.last < p2.last ); }
- int main()
- {
- int n,i,index;
- cin >> n;
- int *out = new int[n];
- pole *column = new pole[n];
- bool *empty = new bool[n];
- for ( i=0; i<n; i++)
- {
- cin >> column[i].first;
- cin >> column[i].last;
- out[i] = -1;
- column[i].index = i;
- empty[i] = true;
- }
- sort(&column[0],&column[n],fun);
- index = 0;
- for ( i=0; i<n; i++ )
- {
- while ( column[i].first <= column[i].last )
- {
- if ( empty[column[i].first] )
- {
- out[column[i].index] = column[i].first;
- empty[column[i].first] = false;
- break;
- }
- column[i].first++;
- }
- }
- bool ok = true;
- for (i=0;i<n;i++)
- if ( out[i] == -1 )
- {
- ok = false;
- break;
- }
- if ( ok )
- for (i=0;i<n;i++)
- cout << out[i] << endl;
- else
- cout << "NIE";
- //system("Pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment