fork download
  1.  
  2. void solve(int testcases){
  3. int n;
  4. cin >> n;
  5. vector<int> v(n);
  6. vector<pair<int, pi>> w(n);
  7.  
  8. for (auto &i: v) cin >> i;
  9.  
  10. for (int i = 0; i < n; i++) {
  11. cin >> w[i].ff;
  12. w[i].ff = 2 * w[i].ff - v[i];
  13. w[i].ss = {i + 1, i + 1};
  14. }
  15. vector<pair<int, pi>> arr;
  16. int nowpos = 0, nowneg = 0;
  17. for (int i = 0; i < n; i++) {
  18. if (arr.empty() || w[i].ff > 0) {
  19. arr.push_back(w[i]);
  20. } else {
  21. if (arr.back().ff <= 0) {
  22. arr.back() = {arr.back().ff + w[i].ff, {arr.back().ss.ff, w[i].ss.ss}};
  23. } else {
  24. arr.push_back(w[i]);
  25. }
  26. }
  27. }
  28. for (auto i : arr) {
  29. if (i.ff > 0) {
  30. nowpos++;
  31. } else {
  32. nowneg++;
  33. }
  34. }
  35. if (nowpos > nowneg) {
  36. vector<pi> ans;
  37. for (auto i : arr) {
  38. if (i.ss.ff != i.ss.ss) {
  39. ans.push_back(i.ss);
  40. }
  41. }
  42. cout << "Yes\n";
  43. cout << ans.size() << endl;
  44. for (auto i : ans) {
  45. cout << i.ff << " " << i.ss << endl;
  46. }
  47. return;
  48. }
  49. int first = -1, last = -1;
  50. for (int i = 0; i < (int) arr.size() - 1; i++) {
  51. if ((arr[i].ff > 0 && arr[i + 1].ff <= 0) || (arr[i].ff <= 0 && arr[i + 1].ff > 0)) {
  52. if (arr[i].ff + arr[i + 1].ff > 0) {
  53. if (first == -1) {
  54. first = i;
  55. }
  56. last = i;
  57. }
  58. }
  59. }
  60. if (first == -1) {
  61. cout << "No\n";
  62. return;
  63. }
  64. if (nowneg == nowpos || last > first + 1) {
  65. vector<pi> ans;
  66. for (int i = 0; i < arr.size(); i++) {
  67. if (i == first || (last > first + 1 && i == last)) {
  68. ans.push_back({arr[i].ss.ff, arr[i + 1].ss.ss});
  69. i++;
  70. } else if (arr[i].ss.ff != arr[i].ss.ss) {
  71. ans.push_back(arr[i].ss);
  72. }
  73. }
  74. cout << "Yes\n";
  75. cout << ans.size() << endl;
  76. for (auto i : ans) {
  77. cout << i.ff << " " << i.ss << endl;
  78. }
  79. return;
  80. }
  81. vector<pi> ans;
  82. int ind = -1;
  83. for (int i = 0; i < (int) arr.size() - 2; i++) {
  84. if (ind == -1 && arr[i].ff <= 0 && arr[i + 1].ff > 0 && arr[i + 2].ff <= 0 && (arr[i].ff + arr[i + 1].ff + arr[i + 2].ff > 0)) {
  85. ind = i;
  86. break;
  87. }
  88. }
  89. if (ind == -1) {
  90. cout << "No\n";
  91. return;
  92. }
  93. cout << "Yes\n";
  94. for (int i = 0; i < (int) arr.size(); i++) {
  95. if (i == ind) {
  96. ans.push_back({arr[i].ss.ff, arr[i + 2].ss.ss});
  97. i += 2;
  98. } else if (arr[i].ss.ff != arr[i].ss.ss) {
  99. ans.push_back(arr[i].ss);
  100. }
  101. }
  102. cout << ans.size() << endl;
  103. for (auto i : ans) {
  104. cout << i.ff << " " << i.ss << endl;
  105. }
  106. }
  107.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘void solve(int)’:
prog.cpp:4:5: error: ‘cin’ was not declared in this scope
     cin >> n;
     ^~~
prog.cpp:5:5: error: ‘vector’ was not declared in this scope
     vector<int> v(n);
     ^~~~~~
prog.cpp:5:12: error: expected primary-expression before ‘int’
     vector<int> v(n);
            ^~~
prog.cpp:6:12: error: ‘pair’ was not declared in this scope
     vector<pair<int, pi>> w(n);
            ^~~~
prog.cpp:6:17: error: expected primary-expression before ‘int’
     vector<pair<int, pi>> w(n);
                 ^~~
prog.cpp:8:19: error: ‘v’ was not declared in this scope
     for (auto &i: v) cin >> i;
                   ^
prog.cpp:11:16: error: ‘w’ was not declared in this scope
         cin >> w[i].ff;
                ^
prog.cpp:12:33: error: ‘v’ was not declared in this scope
         w[i].ff = 2 * w[i].ff - v[i];
                                 ^
prog.cpp:15:17: error: expected primary-expression before ‘int’
     vector<pair<int, pi>> arr;
                 ^~~
prog.cpp:18:13: error: ‘arr’ was not declared in this scope
         if (arr.empty() || w[i].ff > 0) {
             ^~~
prog.cpp:18:28: error: ‘w’ was not declared in this scope
         if (arr.empty() || w[i].ff > 0) {
                            ^
prog.cpp:28:19: error: ‘arr’ was not declared in this scope
     for (auto i : arr) {
                   ^~~
prog.cpp:36:16: error: ‘pi’ was not declared in this scope
         vector<pi> ans;
                ^~
prog.cpp:36:20: error: ‘ans’ was not declared in this scope
         vector<pi> ans;
                    ^~~
prog.cpp:37:23: error: ‘arr’ was not declared in this scope
         for (auto i : arr) {
                       ^~~
prog.cpp:42:9: error: ‘cout’ was not declared in this scope
         cout << "Yes\n";
         ^~~~
prog.cpp:43:31: error: ‘endl’ was not declared in this scope
         cout << ans.size() << endl;
                               ^~~~
prog.cpp:43:31: note: suggested alternative: ‘enum’
         cout << ans.size() << endl;
                               ^~~~
                               enum
prog.cpp:44:23: error: unable to deduce ‘auto&&’ from ‘ans’
         for (auto i : ans) {
                       ^~~
prog.cpp:50:31: error: ‘arr’ was not declared in this scope
     for (int i = 0; i < (int) arr.size() - 1; i++) {
                               ^~~
prog.cpp:61:9: error: ‘cout’ was not declared in this scope
         cout << "No\n";
         ^~~~
prog.cpp:65:16: error: ‘pi’ was not declared in this scope
         vector<pi> ans;
                ^~
prog.cpp:65:20: error: ‘ans’ was not declared in this scope
         vector<pi> ans;
                    ^~~
prog.cpp:66:29: error: ‘arr’ was not declared in this scope
         for (int i = 0; i < arr.size(); i++) {
                             ^~~
prog.cpp:74:9: error: ‘cout’ was not declared in this scope
         cout << "Yes\n";
         ^~~~
prog.cpp:75:31: error: ‘endl’ was not declared in this scope
         cout << ans.size() << endl;
                               ^~~~
prog.cpp:75:31: note: suggested alternative: ‘enum’
         cout << ans.size() << endl;
                               ^~~~
                               enum
prog.cpp:76:23: error: unable to deduce ‘auto&&’ from ‘ans’
         for (auto i : ans) {
                       ^~~
prog.cpp:81:12: error: ‘pi’ was not declared in this scope
     vector<pi> ans;
            ^~
prog.cpp:81:16: error: ‘ans’ was not declared in this scope
     vector<pi> ans;
                ^~~
prog.cpp:83:31: error: ‘arr’ was not declared in this scope
     for (int i = 0; i < (int) arr.size() - 2; i++) {
                               ^~~
prog.cpp:90:9: error: ‘cout’ was not declared in this scope
         cout << "No\n";
         ^~~~
prog.cpp:93:5: error: ‘cout’ was not declared in this scope
     cout << "Yes\n";
     ^~~~
prog.cpp:94:31: error: ‘arr’ was not declared in this scope
     for (int i = 0; i < (int) arr.size(); i++) {
                               ^~~
prog.cpp:102:27: error: ‘endl’ was not declared in this scope
     cout << ans.size() << endl;
                           ^~~~
prog.cpp:102:27: note: suggested alternative: ‘ind’
     cout << ans.size() << endl;
                           ^~~~
                           ind
prog.cpp:103:19: error: unable to deduce ‘auto&&’ from ‘ans’
     for (auto i : ans) {
                   ^~~
stdout
Standard output is empty