Advertisement
FyanRu

Untitled

Nov 9th, 2022
101
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void solve() {
  5. int n; cin >> n;
  6. int k; cin >> k;
  7.  
  8. if (k==0 || k==n) {
  9. cout << "YES\n";
  10. return;
  11. }
  12.  
  13. vector<int> left1; // not compressed
  14. vector<int> right1; // not compressed
  15.  
  16. for (int i = 0; i < k-1; i++) {
  17. int a; cin >> a; left1.push_back(a);
  18. }
  19.  
  20. int me; cin >> me;
  21.  
  22. for (int i = k; i < n; i++) {
  23. int a; cin >> a; right1.push_back(a);
  24. }
  25.  
  26. /**for (int i = 0; i < left1.size(); i++) {
  27. cout << left1[i] << " ";
  28. }
  29. cout << "\n";
  30. for (int i = 0; i < right1.size(); i++) {
  31. cout << right1[i] << " ";
  32. }**/
  33.  
  34. vector<int> left; //compressed
  35. vector<int> right; //compressed
  36.  
  37. int sum = left1[0];
  38.  
  39. for (int i = 1; i < k-1; i++) {
  40. if ((left1[i] < 0 && left1[i-1] < 0) || (left1[i] > 0 && left1[i-1] > 0)) {
  41. sum += left1[i];
  42. if (i==k-2) {
  43. left.push_back(sum);
  44. }
  45. } else {
  46. left.push_back(sum);
  47. sum = left1[i];
  48. if (i==n-1) {
  49. right.push_back(sum);
  50. }
  51. }
  52. }
  53.  
  54. sum = right1[0];
  55.  
  56. for (int i = k; i < n; i++) {
  57. if ((right1[i] < 0 && right1[i-1] < 0) || (right1[i] > 0 && right1[i-1] > 0)) {
  58. sum += right1[i];
  59. if (i==n-1) {
  60. right.push_back(sum);
  61. }
  62. } else {
  63. right.push_back(sum);
  64. sum = right1[i];
  65. if (i==n-1) {
  66. right.push_back(sum);
  67. }
  68. }
  69. }
  70.  
  71.  
  72. for (int i = 0; i < right.size(); i++) {
  73. cout << right[i] << " ";
  74. }
  75.  
  76. }
  77.  
  78. int main() {
  79. solve();
  80. return 0;
  81. }
  82.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement