Advertisement
STANAANDREY

smen mars 1d

Sep 26th, 2019
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int q, x, y, z, smen[103], v[103];
  6.  
  7. int main()
  8. {
  9.  
  10.     int n;
  11.     cout << "n=";
  12.     cin >> n;
  13.     cout << "v:";
  14.     for (int i = 1; i <= n; i++)
  15.         cin >> v[i];
  16.     cout << "q=";
  17.     cin >> q;
  18.     while (q--)
  19.     {
  20.         cin >> x >> y >> z; // aduna intre [x, y] valoarea z
  21.         smen[x] += z;
  22.         smen[y + 1] -= z;
  23.     }
  24.       /*  for (int i =0;i<=n;i++)cout<<smen[i]<<' ';
  25.     cout<<endl;//*/
  26.     for (int i = 1; i <= n; ++i)
  27.     {
  28.         smen[i] += smen[i - 1];
  29.     }
  30.  
  31.     for (int i = 1; i <= n; i++)
  32.     {
  33.         v[i] += smen[i];
  34.     }
  35.     cout << "after smen:" << endl;
  36.     for (int i = 1; i <= n; i++)
  37.         cout << v[i] << ' ';
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement