Advertisement
Malinovsky239

УРКОП 2011: K

Oct 22nd, 2011
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <vector>
  5.  
  6. #define N 1005
  7. #define pb push_back
  8. #define INF int(1e9)
  9.  
  10. #define mp make_pair
  11. #define x  first
  12. #define y second
  13.  
  14. using namespace std;
  15.  
  16. pair<int, int> vect[N];
  17. vector< pair<int, int> > ans;                
  18.  
  19. int main() {
  20.     int n, k;
  21.     cin >> n >> k; 
  22.  
  23.     for (int i = 0; i < n; i++) {
  24.         int x, y;
  25.         cin >> x >> y;
  26.         vect[i] = mp(x, y);
  27.     }
  28.  
  29.     sort(vect, vect + n);
  30.  
  31.     int t = 1;
  32.     while (vect[t].x == vect[t - 1].x && t < n) t++;
  33.  
  34.     if (k == 1) {
  35.         ans.pb( mp(vect[0].x,     vect[0].y) );
  36.         ans.pb( mp(vect[0].x,     vect[0].y - 1) );    
  37.         ans.pb( mp(vect[0].x - 1, vect[0].y - 1) );
  38.         ans.pb( mp(vect[0].x - 1, vect[0].y) );    
  39.     }
  40.  
  41.     if (k == 2) {      
  42.         ans.pb(vect[1]);       
  43.         ans.pb(vect[0]);               
  44.         ans.pb(mp(-INF, INF));
  45.     }
  46.  
  47.     if (k > 2) {
  48.        
  49.         if (t >= k) {      
  50.             ans.pb(vect[k - 1]);
  51.             ans.pb(vect[0]);           
  52.             ans.pb(mp(-INF, INF));
  53.         }
  54.         else {
  55.             ans.pb( mp(vect[k - 1].x,-INF) );
  56.             ans.pb( mp(-INF,-INF) );
  57.             ans.pb( mp(-INF, INF) );
  58.             ans.pb( mp(vect[k - 1].x - 1, INF) );
  59.             ans.pb( vect[k - 1] );
  60.         }
  61.     }
  62.  
  63.     cout << ans.size() << endl;
  64.     for (int i = ans.size() - 1; i >= 0; i--)
  65.         cout << ans[i].first << " " << ans[i].second << endl;
  66.  
  67.     return 0;
  68. }
  69.  
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement