답안 #944626

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
944626 2024-03-13T02:05:33 Z yeediot Two Dishes (JOI19_dishes) C++17
100 / 100
1955 ms 247620 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define pb push_back
#define sz(x) (int)(x.size())
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define vi vector<int>
#define vp vector<pii>
#define vvi vector<vi>
#ifdef local
void setio(){freopen("/Users/iantsai/Library/Mobile Documents/com~apple~CloudDocs/cpp/Empty.md","r",stdin);}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
void setio(){}
#define debug(x...)
#endif
//Don't open the standings during contests.
const int mxn=1e6+5;
vector<int>a(mxn),s(mxn),p(mxn),b(mxn),t(mxn),q(mxn);
int pre[mxn],pre2[mxn];
vector<pii>pt[mxn];
int dif[mxn];
signed main(){
    setio();
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i]>>s[i]>>p[i];
        pre[i]=pre[i-1]+a[i];
    }
    for(int i=1;i<=m;i++){
        cin>>b[i]>>t[i]>>q[i];
        pre2[i]=pre2[i-1]+b[i];
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        if(pre[i]>s[i])continue;
        int x=upper_bound(pre2+1,pre2+m+1,s[i]-pre[i])-pre2;
        ans+=p[i];
        if(x<=m)pt[i].pb({x,-p[i]});
    }
    for(int j=1;j<=m;j++){
        if(pre2[j]>t[j])continue;
        if(pre2[j]+pre[n]<=t[j])ans+=q[j];
        else{
            int y=upper_bound(pre+1,pre+n+1,t[j]-pre2[j])-pre;
            pt[y].pb({j,q[j]});
        }
    }
    set<int>st;
    for(int i=0;i<=n;i++){
        for(auto [x,y]:pt[i]){
            //cout<<x<<' ';
            if(!st.count(x)){
                st.insert(x);
                dif[x]=0;
            }
            dif[x]+=y;
        }
        for(auto [x,fuck]:pt[i]){
            //維護前綴max所以把dif<0的都刪掉
            auto it=st.find(x);
            while(it!=st.end() and dif[*it]<0){
                int temp=dif[*it];
                it=st.erase(it);
                if(it!=st.end())dif[*it]+=temp;
            }
        }
    }
    for(auto i:st)ans+=dif[i];
    cout<<ans<<'\n';
}
 /*
 input:
  2 3 6
  2 1 3
  2 2 2
 */
# 결과 실행 시간 메모리 Grader output
1 Correct 200 ms 108112 KB Output is correct
2 Correct 196 ms 99664 KB Output is correct
3 Correct 121 ms 87636 KB Output is correct
4 Correct 191 ms 101788 KB Output is correct
5 Correct 14 ms 74076 KB Output is correct
6 Correct 161 ms 97556 KB Output is correct
7 Correct 66 ms 82004 KB Output is correct
8 Correct 65 ms 82260 KB Output is correct
9 Correct 124 ms 88088 KB Output is correct
10 Correct 143 ms 94224 KB Output is correct
11 Correct 87 ms 83088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 74280 KB Output is correct
2 Correct 13 ms 74076 KB Output is correct
3 Correct 14 ms 74076 KB Output is correct
4 Correct 15 ms 74076 KB Output is correct
5 Correct 13 ms 74144 KB Output is correct
6 Correct 14 ms 74076 KB Output is correct
7 Correct 14 ms 74076 KB Output is correct
8 Correct 14 ms 74328 KB Output is correct
9 Correct 14 ms 74076 KB Output is correct
10 Correct 16 ms 74076 KB Output is correct
11 Correct 14 ms 74076 KB Output is correct
12 Correct 14 ms 74072 KB Output is correct
13 Correct 14 ms 74076 KB Output is correct
14 Correct 14 ms 74064 KB Output is correct
15 Correct 14 ms 74076 KB Output is correct
16 Correct 13 ms 74092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 74280 KB Output is correct
2 Correct 13 ms 74076 KB Output is correct
3 Correct 14 ms 74076 KB Output is correct
4 Correct 15 ms 74076 KB Output is correct
5 Correct 13 ms 74144 KB Output is correct
6 Correct 14 ms 74076 KB Output is correct
7 Correct 14 ms 74076 KB Output is correct
8 Correct 14 ms 74328 KB Output is correct
9 Correct 14 ms 74076 KB Output is correct
10 Correct 16 ms 74076 KB Output is correct
11 Correct 14 ms 74076 KB Output is correct
12 Correct 14 ms 74072 KB Output is correct
13 Correct 14 ms 74076 KB Output is correct
14 Correct 14 ms 74064 KB Output is correct
15 Correct 14 ms 74076 KB Output is correct
16 Correct 13 ms 74092 KB Output is correct
17 Correct 17 ms 74148 KB Output is correct
18 Correct 16 ms 74332 KB Output is correct
19 Correct 16 ms 74332 KB Output is correct
20 Correct 16 ms 74076 KB Output is correct
21 Correct 16 ms 74332 KB Output is correct
22 Correct 16 ms 74336 KB Output is correct
23 Correct 16 ms 74352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 74280 KB Output is correct
2 Correct 13 ms 74076 KB Output is correct
3 Correct 14 ms 74076 KB Output is correct
4 Correct 15 ms 74076 KB Output is correct
5 Correct 13 ms 74144 KB Output is correct
6 Correct 14 ms 74076 KB Output is correct
7 Correct 14 ms 74076 KB Output is correct
8 Correct 14 ms 74328 KB Output is correct
9 Correct 14 ms 74076 KB Output is correct
10 Correct 16 ms 74076 KB Output is correct
11 Correct 14 ms 74076 KB Output is correct
12 Correct 14 ms 74072 KB Output is correct
13 Correct 14 ms 74076 KB Output is correct
14 Correct 14 ms 74064 KB Output is correct
15 Correct 14 ms 74076 KB Output is correct
16 Correct 13 ms 74092 KB Output is correct
17 Correct 17 ms 74148 KB Output is correct
18 Correct 16 ms 74332 KB Output is correct
19 Correct 16 ms 74332 KB Output is correct
20 Correct 16 ms 74076 KB Output is correct
21 Correct 16 ms 74332 KB Output is correct
22 Correct 16 ms 74336 KB Output is correct
23 Correct 16 ms 74352 KB Output is correct
24 Correct 127 ms 91492 KB Output is correct
25 Correct 173 ms 100032 KB Output is correct
26 Correct 126 ms 93524 KB Output is correct
27 Correct 194 ms 103312 KB Output is correct
28 Correct 146 ms 90724 KB Output is correct
29 Correct 112 ms 85840 KB Output is correct
30 Correct 300 ms 98632 KB Output is correct
31 Correct 88 ms 87240 KB Output is correct
32 Correct 69 ms 83984 KB Output is correct
33 Correct 195 ms 92892 KB Output is correct
34 Correct 246 ms 100232 KB Output is correct
35 Correct 259 ms 93732 KB Output is correct
36 Correct 266 ms 93512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 74280 KB Output is correct
2 Correct 13 ms 74076 KB Output is correct
3 Correct 14 ms 74076 KB Output is correct
4 Correct 15 ms 74076 KB Output is correct
5 Correct 13 ms 74144 KB Output is correct
6 Correct 14 ms 74076 KB Output is correct
7 Correct 14 ms 74076 KB Output is correct
8 Correct 14 ms 74328 KB Output is correct
9 Correct 14 ms 74076 KB Output is correct
10 Correct 16 ms 74076 KB Output is correct
11 Correct 14 ms 74076 KB Output is correct
12 Correct 14 ms 74072 KB Output is correct
13 Correct 14 ms 74076 KB Output is correct
14 Correct 14 ms 74064 KB Output is correct
15 Correct 14 ms 74076 KB Output is correct
16 Correct 13 ms 74092 KB Output is correct
17 Correct 17 ms 74148 KB Output is correct
18 Correct 16 ms 74332 KB Output is correct
19 Correct 16 ms 74332 KB Output is correct
20 Correct 16 ms 74076 KB Output is correct
21 Correct 16 ms 74332 KB Output is correct
22 Correct 16 ms 74336 KB Output is correct
23 Correct 16 ms 74352 KB Output is correct
24 Correct 127 ms 91492 KB Output is correct
25 Correct 173 ms 100032 KB Output is correct
26 Correct 126 ms 93524 KB Output is correct
27 Correct 194 ms 103312 KB Output is correct
28 Correct 146 ms 90724 KB Output is correct
29 Correct 112 ms 85840 KB Output is correct
30 Correct 300 ms 98632 KB Output is correct
31 Correct 88 ms 87240 KB Output is correct
32 Correct 69 ms 83984 KB Output is correct
33 Correct 195 ms 92892 KB Output is correct
34 Correct 246 ms 100232 KB Output is correct
35 Correct 259 ms 93732 KB Output is correct
36 Correct 266 ms 93512 KB Output is correct
37 Correct 144 ms 96336 KB Output is correct
38 Correct 208 ms 105608 KB Output is correct
39 Correct 233 ms 106324 KB Output is correct
40 Correct 146 ms 97360 KB Output is correct
41 Correct 15 ms 74076 KB Output is correct
42 Correct 311 ms 102120 KB Output is correct
43 Correct 198 ms 95312 KB Output is correct
44 Correct 257 ms 102512 KB Output is correct
45 Correct 265 ms 96340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 74280 KB Output is correct
2 Correct 13 ms 74076 KB Output is correct
3 Correct 14 ms 74076 KB Output is correct
4 Correct 15 ms 74076 KB Output is correct
5 Correct 13 ms 74144 KB Output is correct
6 Correct 14 ms 74076 KB Output is correct
7 Correct 14 ms 74076 KB Output is correct
8 Correct 14 ms 74328 KB Output is correct
9 Correct 14 ms 74076 KB Output is correct
10 Correct 16 ms 74076 KB Output is correct
11 Correct 14 ms 74076 KB Output is correct
12 Correct 14 ms 74072 KB Output is correct
13 Correct 14 ms 74076 KB Output is correct
14 Correct 14 ms 74064 KB Output is correct
15 Correct 14 ms 74076 KB Output is correct
16 Correct 13 ms 74092 KB Output is correct
17 Correct 17 ms 74148 KB Output is correct
18 Correct 16 ms 74332 KB Output is correct
19 Correct 16 ms 74332 KB Output is correct
20 Correct 16 ms 74076 KB Output is correct
21 Correct 16 ms 74332 KB Output is correct
22 Correct 16 ms 74336 KB Output is correct
23 Correct 16 ms 74352 KB Output is correct
24 Correct 127 ms 91492 KB Output is correct
25 Correct 173 ms 100032 KB Output is correct
26 Correct 126 ms 93524 KB Output is correct
27 Correct 194 ms 103312 KB Output is correct
28 Correct 146 ms 90724 KB Output is correct
29 Correct 112 ms 85840 KB Output is correct
30 Correct 300 ms 98632 KB Output is correct
31 Correct 88 ms 87240 KB Output is correct
32 Correct 69 ms 83984 KB Output is correct
33 Correct 195 ms 92892 KB Output is correct
34 Correct 246 ms 100232 KB Output is correct
35 Correct 259 ms 93732 KB Output is correct
36 Correct 266 ms 93512 KB Output is correct
37 Correct 144 ms 96336 KB Output is correct
38 Correct 208 ms 105608 KB Output is correct
39 Correct 233 ms 106324 KB Output is correct
40 Correct 146 ms 97360 KB Output is correct
41 Correct 15 ms 74076 KB Output is correct
42 Correct 311 ms 102120 KB Output is correct
43 Correct 198 ms 95312 KB Output is correct
44 Correct 257 ms 102512 KB Output is correct
45 Correct 265 ms 96340 KB Output is correct
46 Correct 692 ms 171736 KB Output is correct
47 Correct 1081 ms 208196 KB Output is correct
48 Correct 1270 ms 216976 KB Output is correct
49 Correct 693 ms 169896 KB Output is correct
50 Correct 1889 ms 188024 KB Output is correct
51 Correct 1101 ms 154576 KB Output is correct
52 Correct 1594 ms 184832 KB Output is correct
53 Correct 1790 ms 180356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 200 ms 108112 KB Output is correct
2 Correct 196 ms 99664 KB Output is correct
3 Correct 121 ms 87636 KB Output is correct
4 Correct 191 ms 101788 KB Output is correct
5 Correct 14 ms 74076 KB Output is correct
6 Correct 161 ms 97556 KB Output is correct
7 Correct 66 ms 82004 KB Output is correct
8 Correct 65 ms 82260 KB Output is correct
9 Correct 124 ms 88088 KB Output is correct
10 Correct 143 ms 94224 KB Output is correct
11 Correct 87 ms 83088 KB Output is correct
12 Correct 18 ms 74280 KB Output is correct
13 Correct 13 ms 74076 KB Output is correct
14 Correct 14 ms 74076 KB Output is correct
15 Correct 15 ms 74076 KB Output is correct
16 Correct 13 ms 74144 KB Output is correct
17 Correct 14 ms 74076 KB Output is correct
18 Correct 14 ms 74076 KB Output is correct
19 Correct 14 ms 74328 KB Output is correct
20 Correct 14 ms 74076 KB Output is correct
21 Correct 16 ms 74076 KB Output is correct
22 Correct 14 ms 74076 KB Output is correct
23 Correct 14 ms 74072 KB Output is correct
24 Correct 14 ms 74076 KB Output is correct
25 Correct 14 ms 74064 KB Output is correct
26 Correct 14 ms 74076 KB Output is correct
27 Correct 13 ms 74092 KB Output is correct
28 Correct 17 ms 74148 KB Output is correct
29 Correct 16 ms 74332 KB Output is correct
30 Correct 16 ms 74332 KB Output is correct
31 Correct 16 ms 74076 KB Output is correct
32 Correct 16 ms 74332 KB Output is correct
33 Correct 16 ms 74336 KB Output is correct
34 Correct 16 ms 74352 KB Output is correct
35 Correct 127 ms 91492 KB Output is correct
36 Correct 173 ms 100032 KB Output is correct
37 Correct 126 ms 93524 KB Output is correct
38 Correct 194 ms 103312 KB Output is correct
39 Correct 146 ms 90724 KB Output is correct
40 Correct 112 ms 85840 KB Output is correct
41 Correct 300 ms 98632 KB Output is correct
42 Correct 88 ms 87240 KB Output is correct
43 Correct 69 ms 83984 KB Output is correct
44 Correct 195 ms 92892 KB Output is correct
45 Correct 246 ms 100232 KB Output is correct
46 Correct 259 ms 93732 KB Output is correct
47 Correct 266 ms 93512 KB Output is correct
48 Correct 144 ms 96336 KB Output is correct
49 Correct 208 ms 105608 KB Output is correct
50 Correct 233 ms 106324 KB Output is correct
51 Correct 146 ms 97360 KB Output is correct
52 Correct 15 ms 74076 KB Output is correct
53 Correct 311 ms 102120 KB Output is correct
54 Correct 198 ms 95312 KB Output is correct
55 Correct 257 ms 102512 KB Output is correct
56 Correct 265 ms 96340 KB Output is correct
57 Correct 203 ms 105760 KB Output is correct
58 Correct 144 ms 95860 KB Output is correct
59 Correct 155 ms 97240 KB Output is correct
60 Correct 240 ms 109140 KB Output is correct
61 Correct 423 ms 110112 KB Output is correct
62 Correct 14 ms 74076 KB Output is correct
63 Correct 316 ms 103688 KB Output is correct
64 Correct 204 ms 97268 KB Output is correct
65 Correct 255 ms 101460 KB Output is correct
66 Correct 277 ms 97108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 200 ms 108112 KB Output is correct
2 Correct 196 ms 99664 KB Output is correct
3 Correct 121 ms 87636 KB Output is correct
4 Correct 191 ms 101788 KB Output is correct
5 Correct 14 ms 74076 KB Output is correct
6 Correct 161 ms 97556 KB Output is correct
7 Correct 66 ms 82004 KB Output is correct
8 Correct 65 ms 82260 KB Output is correct
9 Correct 124 ms 88088 KB Output is correct
10 Correct 143 ms 94224 KB Output is correct
11 Correct 87 ms 83088 KB Output is correct
12 Correct 18 ms 74280 KB Output is correct
13 Correct 13 ms 74076 KB Output is correct
14 Correct 14 ms 74076 KB Output is correct
15 Correct 15 ms 74076 KB Output is correct
16 Correct 13 ms 74144 KB Output is correct
17 Correct 14 ms 74076 KB Output is correct
18 Correct 14 ms 74076 KB Output is correct
19 Correct 14 ms 74328 KB Output is correct
20 Correct 14 ms 74076 KB Output is correct
21 Correct 16 ms 74076 KB Output is correct
22 Correct 14 ms 74076 KB Output is correct
23 Correct 14 ms 74072 KB Output is correct
24 Correct 14 ms 74076 KB Output is correct
25 Correct 14 ms 74064 KB Output is correct
26 Correct 14 ms 74076 KB Output is correct
27 Correct 13 ms 74092 KB Output is correct
28 Correct 17 ms 74148 KB Output is correct
29 Correct 16 ms 74332 KB Output is correct
30 Correct 16 ms 74332 KB Output is correct
31 Correct 16 ms 74076 KB Output is correct
32 Correct 16 ms 74332 KB Output is correct
33 Correct 16 ms 74336 KB Output is correct
34 Correct 16 ms 74352 KB Output is correct
35 Correct 127 ms 91492 KB Output is correct
36 Correct 173 ms 100032 KB Output is correct
37 Correct 126 ms 93524 KB Output is correct
38 Correct 194 ms 103312 KB Output is correct
39 Correct 146 ms 90724 KB Output is correct
40 Correct 112 ms 85840 KB Output is correct
41 Correct 300 ms 98632 KB Output is correct
42 Correct 88 ms 87240 KB Output is correct
43 Correct 69 ms 83984 KB Output is correct
44 Correct 195 ms 92892 KB Output is correct
45 Correct 246 ms 100232 KB Output is correct
46 Correct 259 ms 93732 KB Output is correct
47 Correct 266 ms 93512 KB Output is correct
48 Correct 144 ms 96336 KB Output is correct
49 Correct 208 ms 105608 KB Output is correct
50 Correct 233 ms 106324 KB Output is correct
51 Correct 146 ms 97360 KB Output is correct
52 Correct 15 ms 74076 KB Output is correct
53 Correct 311 ms 102120 KB Output is correct
54 Correct 198 ms 95312 KB Output is correct
55 Correct 257 ms 102512 KB Output is correct
56 Correct 265 ms 96340 KB Output is correct
57 Correct 692 ms 171736 KB Output is correct
58 Correct 1081 ms 208196 KB Output is correct
59 Correct 1270 ms 216976 KB Output is correct
60 Correct 693 ms 169896 KB Output is correct
61 Correct 1889 ms 188024 KB Output is correct
62 Correct 1101 ms 154576 KB Output is correct
63 Correct 1594 ms 184832 KB Output is correct
64 Correct 1790 ms 180356 KB Output is correct
65 Correct 203 ms 105760 KB Output is correct
66 Correct 144 ms 95860 KB Output is correct
67 Correct 155 ms 97240 KB Output is correct
68 Correct 240 ms 109140 KB Output is correct
69 Correct 423 ms 110112 KB Output is correct
70 Correct 14 ms 74076 KB Output is correct
71 Correct 316 ms 103688 KB Output is correct
72 Correct 204 ms 97268 KB Output is correct
73 Correct 255 ms 101460 KB Output is correct
74 Correct 277 ms 97108 KB Output is correct
75 Correct 1155 ms 244564 KB Output is correct
76 Correct 661 ms 197660 KB Output is correct
77 Correct 700 ms 200284 KB Output is correct
78 Correct 1294 ms 247620 KB Output is correct
79 Correct 1955 ms 223420 KB Output is correct
80 Correct 1121 ms 187684 KB Output is correct
81 Correct 1409 ms 205248 KB Output is correct
82 Correct 1776 ms 190464 KB Output is correct
83 Correct 1736 ms 207336 KB Output is correct