fork download
  1. #include<iostream>
  2. #include<string>
  3. #include<vector>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.  
  11. int T;
  12. cin >> T;
  13. cin.ignore();
  14. if (T >= 1 && T <= 5)
  15. {
  16. for (int q = 0; q < T; q++)
  17. {
  18. int n;
  19. size_t pos;
  20. cin >> n;
  21. cin.ignore();
  22.  
  23. if (n >= 1 && n <= 100)
  24. {
  25. vector<int> L;
  26. vector<int> R;
  27. vector<int> C;
  28.  
  29. for (int u = 0; u < n; u++)
  30. {
  31. int a;
  32. cin >> a;
  33. cin.ignore();
  34.  
  35. if (a >= 1 && a <= 100)
  36. {
  37. L.push_back(a);
  38. }
  39.  
  40. }
  41. for (int u = 0; u < n; u++)
  42. {
  43. int a;
  44. cin >> a;
  45. cin.ignore();
  46.  
  47. if (a >= 1 && a <= 100)
  48. {
  49. R.push_back(a);
  50. }
  51. }
  52. for (int u = 0; u < n; u++)
  53. {
  54. int df = (L[u] * R[u]);
  55. C.push_back(df);
  56. }
  57. for (size_t u = 0; u < C.size(); u++)
  58. {
  59. int max = C[0];
  60. if (max < C[u]) {
  61. max = C[u];
  62. pos = u+1;
  63. }
  64.  
  65. if (max == C[u]) {
  66. cout << pos;
  67. if (R.at(pos-1) < R[u]) { pos = u + 1; }
  68. if (R[pos - 1] == R[u]) {
  69. if (pos > u) { pos = u + 1; }
  70. }
  71. }
  72. }
  73. cout << pos << endl;
  74. }
  75. }
  76. }
  77. return 0;
  78. }
Runtime error #stdin #stdout #stderr 0s 3420KB
stdin
2
2
1 2
2 1
4
2 1 4 1
2 4 1 4
stdout
3074788912
stderr
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 3074788911) >= this->size() (which is 2)