Submission #252707

# Submission time Handle Problem Language Result Execution time Memory
252707 2020-07-26T07:13:41 Z Vladikus004 Go (COCI18_go) C++14
60 / 100
1 ms 384 KB
#include <bits/stdc++.h>
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;

const int M = 100 + 3, T = 2000 + 3, N = 1000 + 3;
int n, k, m, a[M], b[M], t[M], fenw[T], _b[N], _t[N];

void add(int ind, int x){
    if (ind < 0) return;
    for (int i = ind; i < T; i |= i + 1)
        fenw[i] += x;
}

int get(int ind){
    int ans = 0;
    for (int i = ind; i >= 0; i = (i & (i + 1)) - 1)
        ans += fenw[i];
    return ans;
}

int get_sum(int l, int r){
    if (!l) return get(r);
    return get(r) - get(l - 1);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif // LOCAL
    cin >> n >> k >> m;
    for (int i = 0; i < m; i++){
        cin >> a[i] >> b[i] >> t[i];
        _b[a[i]] = b[i];
        _t[a[i]] = t[i];
    }
    for (int i = k + 1; i <= n; i++){
        if (_b[i])
            add(_t[i] - (i - k) - 1, _b[i]);
    }
//    cout << get_sum(0, T - 1) << "\n";
    int sum = 0, mx = 0;
    for (int i = k; i >= 1; i--){
        if (k - i < _t[i])
            sum += _b[i];
        mx = max(mx, sum + get_sum((k - i) * 2, T - 1));
    }
    cout << mx;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Incorrect 0 ms 384 KB Output isn't correct
6 Incorrect 0 ms 384 KB Output isn't correct
7 Incorrect 0 ms 384 KB Output isn't correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Incorrect 0 ms 384 KB Output isn't correct