1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; inline ll qpow(ll a,ll b,ll mod){ll res=1;while(b){if(b&1)res = (res*a)%mod;a=(a*a)%mod;b>>=1;}return res;} const double eps = 1e-8; const int INF = 0x3f3f3f3f; const int mod = 1e9+7; const int MAXN = 2e5 + 7;
struct node{ int l, r; int mid(){return (l+r)>>1;} int val; }s[MAXN<<1]; ll a[MAXN], b[MAXN], dp[MAXN]; void build(int l, int r, int x){ s[x].l = l; s[x].r = r; s[x].val = 500; int mid = (l+r)>>1; if(l == r) return; build(l, mid, x<<1); build(mid+1, r, x<<1|1); } inline void upd(int l, int r, int x, int v){ if(s[x].l >= l && s[x].r <= r){ s[x].val = min(s[x].val, v); return; } int mid = s[x].mid(); if(r > mid) upd(l, r, x<<1|1, v); if(l <= mid) upd(l, r, x<<1, v); } inline void pushdown(int x){ if(s[x].l == s[x].r){ a[s[x].l] = s[x].val; return; } s[x<<1].val = min(s[x<<1].val, s[x].val); s[x<<1|1].val = min(s[x<<1|1].val, s[x].val); pushdown(x<<1); pushdown(x<<1|1); } int main(int argc, char const *argv[]) { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif int n, k, m; cin >> n >> k >> m; for(int i = 1; i <= n; ++i) cin >> b[i]; build(1, n, 1); int l, r; ll c; for(int i = 1; i <= m; ++i){ cin >> l >> r >> c; upd(l, r, 1, c); } pushdown(1); ll sum = 0; for(int i = 1; i <= n; ++i){ sum += b[i]; if(b[i] >= 0) continue; for(int j = k; j >= a[i]; --j){ dp[j] = max(dp[j], dp[j-a[i]] - b[i]); } } cout << sum+dp[k] << endl; return 0; }
|