fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int s,n,c[1000004],p[1000004];
  4. struct str
  5. {
  6. int a,b;
  7. bool operator < (const str & o) const
  8. {
  9. if((a-b)<(o.a-o.b)) return true;
  10. return false;
  11. }
  12. };
  13.  
  14. void print_prio(priority_queue <str> pq)
  15. {
  16. while (!pq.empty())
  17. {
  18. cout << (pq.top()).a << ' ' << (pq.top()).b << endl;
  19. pq.pop();
  20. }
  21. cout << endl;
  22. }
  23.  
  24. int main()
  25. {
  26. ios_base::sync_with_stdio(0);
  27. cin.tie(0);cout.tie(0);
  28. //freopen("22.inp","r",stdin);
  29. //freopen("22.out","w",stdout);
  30. cin>>n;
  31. priority_queue<str> q;
  32. for(int i=1;i<=n;i++) cin>>c[i]>>p[i];
  33. for(int i=1;i<=n;i++)
  34. {
  35. q.push({c[i],p[i]});
  36. s+=c[i];
  37. cout << i << endl;
  38. print_prio(q);
  39. if(i%2!=0)
  40. {
  41. cout << "Pairing " << i << " pilot with someone\n";
  42. str x=q.top();
  43. s=s-(x.a-x.b);
  44. q.pop();
  45. }
  46. }
  47. cout<<s;
  48. }
Success #stdin #stdout 0.01s 5624KB
stdin
6
10000 7000
9000 3000
6000 4000
5000 1000
9000 3000
8000 6000
stdout
1
10000 7000

Pairing 1 pilot with someone
2
9000 3000

3
9000 3000
6000 4000

Pairing 3 pilot with someone
4
5000 1000
6000 4000

5
9000 3000
5000 1000
6000 4000

Pairing 5 pilot with someone
6
5000 1000
6000 4000
8000 6000

32000