Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- void solve() {
- int n; cin >> n;
- int k; cin >> k;
- if (k==0 || k==n) {
- cout << "YES\n";
- return;
- }
- vector<int> left1; // not compressed
- vector<int> right1; // not compressed
- for (int i = 0; i < k-1; i++) {
- int a; cin >> a; left1.push_back(a);
- }
- int me; cin >> me;
- for (int i = k; i < n; i++) {
- int a; cin >> a; right1.push_back(a);
- }
- /**for (int i = 0; i < left1.size(); i++) {
- cout << left1[i] << " ";
- }
- cout << "\n";
- for (int i = 0; i < right1.size(); i++) {
- cout << right1[i] << " ";
- }**/
- vector<int> left; //compressed
- vector<int> right; //compressed
- int sum = left1[0];
- for (int i = 1; i < k-1; i++) {
- if ((left1[i] < 0 && left1[i-1] < 0) || (left1[i] > 0 && left1[i-1] > 0)) {
- sum += left1[i];
- if (i==k-2) {
- left.push_back(sum);
- }
- } else {
- left.push_back(sum);
- sum = left1[i];
- if (i==n-1) {
- right.push_back(sum);
- }
- }
- }
- sum = right1[0];
- for (int i = k; i < n; i++) {
- if ((right1[i] < 0 && right1[i-1] < 0) || (right1[i] > 0 && right1[i-1] > 0)) {
- sum += right1[i];
- if (i==n-1) {
- right.push_back(sum);
- }
- } else {
- right.push_back(sum);
- sum = right1[i];
- if (i==n-1) {
- right.push_back(sum);
- }
- }
- }
- for (int i = 0; i < right.size(); i++) {
- cout << right[i] << " ";
- }
- }
- int main() {
- solve();
- return 0;
- }
Advertisement
Advertisement