---
# System prepended metadata

title: Codeforces Round 1074 (Div. 4)

---

# pA
AC code:

```Cpp=
#include <bits/stdc++.h>
using namespace std;
int main() {
    int k;
    cin>>k;
    while (k--) {
        int n;
        cin>>n;
        for (int i=1;i<=n;i++) {
            cout << i << " ";
        }
    }
}
```
# pB

```Cpp=
#include <bits/stdc++.h>
using namespace std;
long long value(const vector<int>& a) {
    long long sum = 0;
    int pre_max = 0;
    for (int x : a) {
        pre_max = max(pre_max, x);
        sum += pre_max;
    }
    return sum;
}
void solve() {
    int n;
    cin>>n;
    vector<int> v(n);
    for (int i=0;i<n;i++) cin>>v[i];
    long long ans=value(v);
    for (int i=0;i<n;i++) {
        for (int j=i+1;j<n;j++) {
            swap(v[i],v[j]);
            ans = max(ans,value(v));
            swap(v[i],v[j]);
        }
    }
    cout << ans << "\n";
}
int main() {
    int n;
    cin>>n;
    while (n--) solve();
}
```
# pC

```cpp=
#include <bits/stdc++.h>
using namespace std;
void solve() {
    int n;
    cin >> n;
    vector<long long> v;
    for (int i = 0; i < n; i++) {
        long long num;
        cin >> num;
        v.push_back(num);
    }

    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    int max_len = 0;
    int current_len = 0;
    for (int i = 0; i < v.size(); i++) {
        if (i == 0) current_len = 1;
        else {
            if (v[i] == v[i-1] + 1) current_len++;
            else {
                max_len = max(max_len, current_len);
                current_len = 1;
            }
        }
    }
    max_len = max(max_len, current_len);
    cout << max_len << "\n";
}
int main() {
    int k;
    cin>>k;
    while (k--) solve();
}
```
# pD
```cpp=
#include <bits/stdc++.h>
using namespace std;
void solve() {
    int n,m,h;
    cin>>n>>m>>h;
    vector<long long> v(n+1);
    vector<long long> cur(n+1);
    for (int i=1;i<=n;i++) {
        cin>>v[i];
        cur[i]=v[i];
    }
    vector<int> st;
    for (int i=0;i<m;i++) {
        int a,b;
        cin>>a>>b;
        cur[a]+=b;
        st.push_back(a);
        if (cur[a]>h) {
            for (int idx :st) cur[idx] = v[idx];
            st.clear();
        }
    }
    for (int i = 1; i <= n; i++) cout << cur[i] << " ";
    cout << "\n";
}
int main() {
    ios::sync_with_stdio(0),cin.tie(0);
    int n;
    cin>>n;
    while (n--) solve();
}
```
# pE
```cpp=
#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9 + 7;

void solve() {
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<int> b(m);
    for (int i = 0; i < m; i++) cin >> b[i];
    string gdCode;
    cin >> gdCode;
    sort(b.begin(), b.end());
    vector<pair<int, int>> deathL, deathR;
    for (int i = 0; i < n; i++) {
        auto it = lower_bound(b.begin(), b.end(), a[i]);
        if (it != b.end()) {
            deathR.push_back({*it - a[i], i});
        }
        if (it != b.begin()) {
            deathL.push_back({a[i] - *prev(it), i});
        }
    }
    sort(deathL.begin(), deathL.end());
    sort(deathR.begin(), deathR.end());
    int cur_pos = 0;
    int min_pos = 0;
    int max_pos = 0;
    int ptr_L = 0;
    int ptr_R = 0;
    int alive_cnt = n;
    vector<bool> is_dead(n, false);
    for (char move : gdCode) {
        if (move == 'L') cur_pos--;
        else cur_pos++;
        if (cur_pos < min_pos) {
            min_pos = cur_pos;
            int dist_moved_left = abs(min_pos);
            while (ptr_L < deathL.size() && deathL[ptr_L].first <= dist_moved_left) {
                int robot_idx = deathL[ptr_L].second;
                if (!is_dead[robot_idx]) {
                    is_dead[robot_idx] = true;
                    alive_cnt--;
                }
                ptr_L++;
            }
        }
        if (cur_pos > max_pos) {
            max_pos = cur_pos;
            int dist_moved_right = max_pos;
            while (ptr_R < deathR.size() && deathR[ptr_R].first <= dist_moved_right) {
                int robot_idx = deathR[ptr_R].second;
                if (!is_dead[robot_idx]) {
                    is_dead[robot_idx] = true;
                    alive_cnt--;
                }
                ptr_R++;
            }
        }
        cout << alive_cnt << " ";
    }
    cout << "\n";
}

int main() {
    ios_base::sync_with_stdio(0),cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
```