Submission #269819

# Submission time Handle Problem Language Result Execution time Memory
269819 2020-08-17T10:34:05 Z kaplanbar Go (COCI18_go) C++14
60 / 100
2 ms 1920 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct Pk {
    ll a, b, t;
    bool operator<(const Pk other) const {
        return a < other.a;
    }
};
ll n, k, m, sz1, sz2, dp[105][2005];
Pk v1[105],v2[105];
ll f(int idx, int T) {
    if(idx>=sz1) return 0;
    if(~dp[idx][T]) return dp[idx][T];
    ll ret=0;
    if(T<v1[idx].t) ret+=v1[idx].b;
    if(idx!=sz1-1) {
        ret+=f(idx+1,T+v1[idx+1].a-v1[idx].a);
    }
    return dp[idx][T]=ret;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    memset(dp,-1,sizeof dp);
    cin >> n >> k >> m;
    ll ans=0;
    for(int i = 0; i < m; i++) {
        int a, b, t;
        cin >> a >> b >> t;
        if(a==k) {
            ans += b;
            continue;
        }
        if(a>k) v1[sz1++]={a,b,t};
        else v2[sz2++]={a,b,t};
    }
    sort(v1, v1+sz1);
    
    sort(v2, v2+sz2);
    reverse(v2, v2+sz2);

    ans += sz1 ? f(0,v1[0].a-k) : 0;

    ll sum = 0;

    for(int i = 0; i < sz2; i++) {
        if(v2[i].t > k - v2[i].a) {
            sum += v2[i].b;
        }
        ll r = sz1 ? f(0, k - v2[i].a + v1[0].a - v2[i].a) : 0ll;
        ans = max(ans, sum + r);
    }

    cout << ans;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1920 KB Output is correct
2 Correct 2 ms 1920 KB Output is correct
3 Correct 1 ms 1920 KB Output is correct
4 Correct 1 ms 1920 KB Output is correct
5 Incorrect 1 ms 1920 KB Output isn't correct
6 Incorrect 1 ms 1920 KB Output isn't correct
7 Incorrect 2 ms 1920 KB Output isn't correct
8 Correct 2 ms 1920 KB Output is correct
9 Correct 2 ms 1920 KB Output is correct
10 Incorrect 2 ms 1920 KB Output isn't correct