fork(1) download
  1. // druva_challenge.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #define _CRT_DISABLE_PERFCRIT_LOCKS
  5.  
  6. // lower_bound/upper_bound example
  7. #include <iostream> // std::cout
  8. #include <algorithm> // std::lower_bound, std::upper_bound, std::sort
  9. #include <vector> // std::vector
  10. #include <utility>
  11.  
  12. using namespace std;
  13.  
  14.  
  15. bool pairCompare(const std::pair<long long int, unsigned int>& firstElem, const std::pair<long long int, unsigned int>& secondElem) {
  16. return firstElem.first < secondElem.first;
  17.  
  18. }
  19.  
  20. int main() {
  21.  
  22. ios_base::sync_with_stdio(false);
  23. cin.tie(NULL);
  24.  
  25. unsigned int n, m;
  26.  
  27. long long int arr[100000], x,temp;
  28.  
  29. vector<pair<long long int, unsigned int> > vect(100000);
  30.  
  31. cin >> n;
  32.  
  33. for (unsigned int i = 0; i < n; i++)
  34. {
  35. cin >> temp;
  36. arr[i] = temp;
  37.  
  38. vect[i].first = temp;
  39. vect[i].second = i;
  40. }
  41.  
  42. sort(vect.begin(), vect.begin() + n, pairCompare);
  43.  
  44.  
  45. cin >> m;
  46.  
  47. vector<pair<long long int, unsigned int> >::iterator low;
  48.  
  49.  
  50.  
  51. while (m--)
  52. {
  53. cin >> x;
  54.  
  55.  
  56.  
  57. low = lower_bound(vect.begin(), vect.begin() + n, make_pair(x,2), pairCompare);
  58.  
  59. if (low != vect.begin() + n)
  60. {
  61.  
  62. for (unsigned int i = low - vect.begin(); i < n; i++)
  63. {
  64.  
  65. if (vect[i].first != x)
  66. {
  67. vect[i].first -= 1;
  68.  
  69. arr[vect[i].second] -= 1;
  70. }
  71. }
  72. }
  73.  
  74.  
  75.  
  76.  
  77. }
  78.  
  79.  
  80. for (unsigned int i = 0; i < n; i++)
  81. {
  82.  
  83. cout << arr[i]<<" ";
  84. }
  85.  
  86.  
  87. return 0;
  88. }
Success #stdin #stdout 0s 4132KB
stdin
Standard input is empty
stdout
Standard output is empty