Submission #862213

# Submission time Handle Problem Language Result Execution time Memory
862213 2023-10-17T17:33:22 Z yeediot Two Dishes (JOI19_dishes) C++14
100 / 100
1915 ms 246648 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>
//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(){
    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++){
        sort(all(pt[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
 */

Compilation message

dishes.cpp: In function 'int main()':
dishes.cpp:52:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   52 |         for(auto [x,y]:pt[i]){
      |                  ^
dishes.cpp:60:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   60 |         for(auto [x,fuck]:pt[i]){
      |                  ^
# Verdict Execution time Memory Grader output
1 Correct 202 ms 109572 KB Output is correct
2 Correct 162 ms 101652 KB Output is correct
3 Correct 119 ms 89424 KB Output is correct
4 Correct 186 ms 103760 KB Output is correct
5 Correct 13 ms 74076 KB Output is correct
6 Correct 162 ms 99484 KB Output is correct
7 Correct 65 ms 82772 KB Output is correct
8 Correct 64 ms 83028 KB Output is correct
9 Correct 120 ms 90524 KB Output is correct
10 Correct 143 ms 95376 KB Output is correct
11 Correct 86 ms 83796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 74080 KB Output is correct
2 Correct 13 ms 74072 KB Output is correct
3 Correct 14 ms 74076 KB Output is correct
4 Correct 13 ms 74076 KB Output is correct
5 Correct 14 ms 74012 KB Output is correct
6 Correct 13 ms 74076 KB Output is correct
7 Correct 14 ms 73964 KB Output is correct
8 Correct 13 ms 74060 KB Output is correct
9 Correct 13 ms 74076 KB Output is correct
10 Correct 13 ms 74096 KB Output is correct
11 Correct 13 ms 74076 KB Output is correct
12 Correct 13 ms 74140 KB Output is correct
13 Correct 13 ms 74076 KB Output is correct
14 Correct 14 ms 74148 KB Output is correct
15 Correct 13 ms 74148 KB Output is correct
16 Correct 13 ms 74076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 74080 KB Output is correct
2 Correct 13 ms 74072 KB Output is correct
3 Correct 14 ms 74076 KB Output is correct
4 Correct 13 ms 74076 KB Output is correct
5 Correct 14 ms 74012 KB Output is correct
6 Correct 13 ms 74076 KB Output is correct
7 Correct 14 ms 73964 KB Output is correct
8 Correct 13 ms 74060 KB Output is correct
9 Correct 13 ms 74076 KB Output is correct
10 Correct 13 ms 74096 KB Output is correct
11 Correct 13 ms 74076 KB Output is correct
12 Correct 13 ms 74140 KB Output is correct
13 Correct 13 ms 74076 KB Output is correct
14 Correct 14 ms 74148 KB Output is correct
15 Correct 13 ms 74148 KB Output is correct
16 Correct 13 ms 74076 KB Output is correct
17 Correct 14 ms 74076 KB Output is correct
18 Correct 14 ms 74332 KB Output is correct
19 Correct 15 ms 74340 KB Output is correct
20 Correct 14 ms 74248 KB Output is correct
21 Correct 15 ms 74332 KB Output is correct
22 Correct 15 ms 74332 KB Output is correct
23 Correct 16 ms 74328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 74080 KB Output is correct
2 Correct 13 ms 74072 KB Output is correct
3 Correct 14 ms 74076 KB Output is correct
4 Correct 13 ms 74076 KB Output is correct
5 Correct 14 ms 74012 KB Output is correct
6 Correct 13 ms 74076 KB Output is correct
7 Correct 14 ms 73964 KB Output is correct
8 Correct 13 ms 74060 KB Output is correct
9 Correct 13 ms 74076 KB Output is correct
10 Correct 13 ms 74096 KB Output is correct
11 Correct 13 ms 74076 KB Output is correct
12 Correct 13 ms 74140 KB Output is correct
13 Correct 13 ms 74076 KB Output is correct
14 Correct 14 ms 74148 KB Output is correct
15 Correct 13 ms 74148 KB Output is correct
16 Correct 13 ms 74076 KB Output is correct
17 Correct 14 ms 74076 KB Output is correct
18 Correct 14 ms 74332 KB Output is correct
19 Correct 15 ms 74340 KB Output is correct
20 Correct 14 ms 74248 KB Output is correct
21 Correct 15 ms 74332 KB Output is correct
22 Correct 15 ms 74332 KB Output is correct
23 Correct 16 ms 74328 KB Output is correct
24 Correct 122 ms 93008 KB Output is correct
25 Correct 177 ms 101740 KB Output is correct
26 Correct 125 ms 94868 KB Output is correct
27 Correct 186 ms 104724 KB Output is correct
28 Correct 150 ms 91988 KB Output is correct
29 Correct 104 ms 87336 KB Output is correct
30 Correct 288 ms 100436 KB Output is correct
31 Correct 88 ms 87760 KB Output is correct
32 Correct 66 ms 84568 KB Output is correct
33 Correct 182 ms 94224 KB Output is correct
34 Correct 235 ms 101672 KB Output is correct
35 Correct 254 ms 94484 KB Output is correct
36 Correct 249 ms 93948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 74080 KB Output is correct
2 Correct 13 ms 74072 KB Output is correct
3 Correct 14 ms 74076 KB Output is correct
4 Correct 13 ms 74076 KB Output is correct
5 Correct 14 ms 74012 KB Output is correct
6 Correct 13 ms 74076 KB Output is correct
7 Correct 14 ms 73964 KB Output is correct
8 Correct 13 ms 74060 KB Output is correct
9 Correct 13 ms 74076 KB Output is correct
10 Correct 13 ms 74096 KB Output is correct
11 Correct 13 ms 74076 KB Output is correct
12 Correct 13 ms 74140 KB Output is correct
13 Correct 13 ms 74076 KB Output is correct
14 Correct 14 ms 74148 KB Output is correct
15 Correct 13 ms 74148 KB Output is correct
16 Correct 13 ms 74076 KB Output is correct
17 Correct 14 ms 74076 KB Output is correct
18 Correct 14 ms 74332 KB Output is correct
19 Correct 15 ms 74340 KB Output is correct
20 Correct 14 ms 74248 KB Output is correct
21 Correct 15 ms 74332 KB Output is correct
22 Correct 15 ms 74332 KB Output is correct
23 Correct 16 ms 74328 KB Output is correct
24 Correct 122 ms 93008 KB Output is correct
25 Correct 177 ms 101740 KB Output is correct
26 Correct 125 ms 94868 KB Output is correct
27 Correct 186 ms 104724 KB Output is correct
28 Correct 150 ms 91988 KB Output is correct
29 Correct 104 ms 87336 KB Output is correct
30 Correct 288 ms 100436 KB Output is correct
31 Correct 88 ms 87760 KB Output is correct
32 Correct 66 ms 84568 KB Output is correct
33 Correct 182 ms 94224 KB Output is correct
34 Correct 235 ms 101672 KB Output is correct
35 Correct 254 ms 94484 KB Output is correct
36 Correct 249 ms 93948 KB Output is correct
37 Correct 141 ms 98336 KB Output is correct
38 Correct 203 ms 107652 KB Output is correct
39 Correct 238 ms 108208 KB Output is correct
40 Correct 154 ms 98720 KB Output is correct
41 Correct 13 ms 74076 KB Output is correct
42 Correct 297 ms 103204 KB Output is correct
43 Correct 197 ms 97364 KB Output is correct
44 Correct 252 ms 104340 KB Output is correct
45 Correct 268 ms 97300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 74080 KB Output is correct
2 Correct 13 ms 74072 KB Output is correct
3 Correct 14 ms 74076 KB Output is correct
4 Correct 13 ms 74076 KB Output is correct
5 Correct 14 ms 74012 KB Output is correct
6 Correct 13 ms 74076 KB Output is correct
7 Correct 14 ms 73964 KB Output is correct
8 Correct 13 ms 74060 KB Output is correct
9 Correct 13 ms 74076 KB Output is correct
10 Correct 13 ms 74096 KB Output is correct
11 Correct 13 ms 74076 KB Output is correct
12 Correct 13 ms 74140 KB Output is correct
13 Correct 13 ms 74076 KB Output is correct
14 Correct 14 ms 74148 KB Output is correct
15 Correct 13 ms 74148 KB Output is correct
16 Correct 13 ms 74076 KB Output is correct
17 Correct 14 ms 74076 KB Output is correct
18 Correct 14 ms 74332 KB Output is correct
19 Correct 15 ms 74340 KB Output is correct
20 Correct 14 ms 74248 KB Output is correct
21 Correct 15 ms 74332 KB Output is correct
22 Correct 15 ms 74332 KB Output is correct
23 Correct 16 ms 74328 KB Output is correct
24 Correct 122 ms 93008 KB Output is correct
25 Correct 177 ms 101740 KB Output is correct
26 Correct 125 ms 94868 KB Output is correct
27 Correct 186 ms 104724 KB Output is correct
28 Correct 150 ms 91988 KB Output is correct
29 Correct 104 ms 87336 KB Output is correct
30 Correct 288 ms 100436 KB Output is correct
31 Correct 88 ms 87760 KB Output is correct
32 Correct 66 ms 84568 KB Output is correct
33 Correct 182 ms 94224 KB Output is correct
34 Correct 235 ms 101672 KB Output is correct
35 Correct 254 ms 94484 KB Output is correct
36 Correct 249 ms 93948 KB Output is correct
37 Correct 141 ms 98336 KB Output is correct
38 Correct 203 ms 107652 KB Output is correct
39 Correct 238 ms 108208 KB Output is correct
40 Correct 154 ms 98720 KB Output is correct
41 Correct 13 ms 74076 KB Output is correct
42 Correct 297 ms 103204 KB Output is correct
43 Correct 197 ms 97364 KB Output is correct
44 Correct 252 ms 104340 KB Output is correct
45 Correct 268 ms 97300 KB Output is correct
46 Correct 671 ms 195348 KB Output is correct
47 Correct 1040 ms 242328 KB Output is correct
48 Correct 1396 ms 244224 KB Output is correct
49 Correct 686 ms 197664 KB Output is correct
50 Correct 1846 ms 221976 KB Output is correct
51 Correct 1109 ms 187556 KB Output is correct
52 Correct 1612 ms 217492 KB Output is correct
53 Correct 1861 ms 189004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 202 ms 109572 KB Output is correct
2 Correct 162 ms 101652 KB Output is correct
3 Correct 119 ms 89424 KB Output is correct
4 Correct 186 ms 103760 KB Output is correct
5 Correct 13 ms 74076 KB Output is correct
6 Correct 162 ms 99484 KB Output is correct
7 Correct 65 ms 82772 KB Output is correct
8 Correct 64 ms 83028 KB Output is correct
9 Correct 120 ms 90524 KB Output is correct
10 Correct 143 ms 95376 KB Output is correct
11 Correct 86 ms 83796 KB Output is correct
12 Correct 14 ms 74080 KB Output is correct
13 Correct 13 ms 74072 KB Output is correct
14 Correct 14 ms 74076 KB Output is correct
15 Correct 13 ms 74076 KB Output is correct
16 Correct 14 ms 74012 KB Output is correct
17 Correct 13 ms 74076 KB Output is correct
18 Correct 14 ms 73964 KB Output is correct
19 Correct 13 ms 74060 KB Output is correct
20 Correct 13 ms 74076 KB Output is correct
21 Correct 13 ms 74096 KB Output is correct
22 Correct 13 ms 74076 KB Output is correct
23 Correct 13 ms 74140 KB Output is correct
24 Correct 13 ms 74076 KB Output is correct
25 Correct 14 ms 74148 KB Output is correct
26 Correct 13 ms 74148 KB Output is correct
27 Correct 13 ms 74076 KB Output is correct
28 Correct 14 ms 74076 KB Output is correct
29 Correct 14 ms 74332 KB Output is correct
30 Correct 15 ms 74340 KB Output is correct
31 Correct 14 ms 74248 KB Output is correct
32 Correct 15 ms 74332 KB Output is correct
33 Correct 15 ms 74332 KB Output is correct
34 Correct 16 ms 74328 KB Output is correct
35 Correct 122 ms 93008 KB Output is correct
36 Correct 177 ms 101740 KB Output is correct
37 Correct 125 ms 94868 KB Output is correct
38 Correct 186 ms 104724 KB Output is correct
39 Correct 150 ms 91988 KB Output is correct
40 Correct 104 ms 87336 KB Output is correct
41 Correct 288 ms 100436 KB Output is correct
42 Correct 88 ms 87760 KB Output is correct
43 Correct 66 ms 84568 KB Output is correct
44 Correct 182 ms 94224 KB Output is correct
45 Correct 235 ms 101672 KB Output is correct
46 Correct 254 ms 94484 KB Output is correct
47 Correct 249 ms 93948 KB Output is correct
48 Correct 141 ms 98336 KB Output is correct
49 Correct 203 ms 107652 KB Output is correct
50 Correct 238 ms 108208 KB Output is correct
51 Correct 154 ms 98720 KB Output is correct
52 Correct 13 ms 74076 KB Output is correct
53 Correct 297 ms 103204 KB Output is correct
54 Correct 197 ms 97364 KB Output is correct
55 Correct 252 ms 104340 KB Output is correct
56 Correct 268 ms 97300 KB Output is correct
57 Correct 201 ms 108112 KB Output is correct
58 Correct 144 ms 98804 KB Output is correct
59 Correct 156 ms 99804 KB Output is correct
60 Correct 246 ms 108944 KB Output is correct
61 Correct 407 ms 110188 KB Output is correct
62 Correct 13 ms 74076 KB Output is correct
63 Correct 307 ms 103788 KB Output is correct
64 Correct 237 ms 97040 KB Output is correct
65 Correct 248 ms 101392 KB Output is correct
66 Correct 280 ms 97180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 202 ms 109572 KB Output is correct
2 Correct 162 ms 101652 KB Output is correct
3 Correct 119 ms 89424 KB Output is correct
4 Correct 186 ms 103760 KB Output is correct
5 Correct 13 ms 74076 KB Output is correct
6 Correct 162 ms 99484 KB Output is correct
7 Correct 65 ms 82772 KB Output is correct
8 Correct 64 ms 83028 KB Output is correct
9 Correct 120 ms 90524 KB Output is correct
10 Correct 143 ms 95376 KB Output is correct
11 Correct 86 ms 83796 KB Output is correct
12 Correct 14 ms 74080 KB Output is correct
13 Correct 13 ms 74072 KB Output is correct
14 Correct 14 ms 74076 KB Output is correct
15 Correct 13 ms 74076 KB Output is correct
16 Correct 14 ms 74012 KB Output is correct
17 Correct 13 ms 74076 KB Output is correct
18 Correct 14 ms 73964 KB Output is correct
19 Correct 13 ms 74060 KB Output is correct
20 Correct 13 ms 74076 KB Output is correct
21 Correct 13 ms 74096 KB Output is correct
22 Correct 13 ms 74076 KB Output is correct
23 Correct 13 ms 74140 KB Output is correct
24 Correct 13 ms 74076 KB Output is correct
25 Correct 14 ms 74148 KB Output is correct
26 Correct 13 ms 74148 KB Output is correct
27 Correct 13 ms 74076 KB Output is correct
28 Correct 14 ms 74076 KB Output is correct
29 Correct 14 ms 74332 KB Output is correct
30 Correct 15 ms 74340 KB Output is correct
31 Correct 14 ms 74248 KB Output is correct
32 Correct 15 ms 74332 KB Output is correct
33 Correct 15 ms 74332 KB Output is correct
34 Correct 16 ms 74328 KB Output is correct
35 Correct 122 ms 93008 KB Output is correct
36 Correct 177 ms 101740 KB Output is correct
37 Correct 125 ms 94868 KB Output is correct
38 Correct 186 ms 104724 KB Output is correct
39 Correct 150 ms 91988 KB Output is correct
40 Correct 104 ms 87336 KB Output is correct
41 Correct 288 ms 100436 KB Output is correct
42 Correct 88 ms 87760 KB Output is correct
43 Correct 66 ms 84568 KB Output is correct
44 Correct 182 ms 94224 KB Output is correct
45 Correct 235 ms 101672 KB Output is correct
46 Correct 254 ms 94484 KB Output is correct
47 Correct 249 ms 93948 KB Output is correct
48 Correct 141 ms 98336 KB Output is correct
49 Correct 203 ms 107652 KB Output is correct
50 Correct 238 ms 108208 KB Output is correct
51 Correct 154 ms 98720 KB Output is correct
52 Correct 13 ms 74076 KB Output is correct
53 Correct 297 ms 103204 KB Output is correct
54 Correct 197 ms 97364 KB Output is correct
55 Correct 252 ms 104340 KB Output is correct
56 Correct 268 ms 97300 KB Output is correct
57 Correct 671 ms 195348 KB Output is correct
58 Correct 1040 ms 242328 KB Output is correct
59 Correct 1396 ms 244224 KB Output is correct
60 Correct 686 ms 197664 KB Output is correct
61 Correct 1846 ms 221976 KB Output is correct
62 Correct 1109 ms 187556 KB Output is correct
63 Correct 1612 ms 217492 KB Output is correct
64 Correct 1861 ms 189004 KB Output is correct
65 Correct 201 ms 108112 KB Output is correct
66 Correct 144 ms 98804 KB Output is correct
67 Correct 156 ms 99804 KB Output is correct
68 Correct 246 ms 108944 KB Output is correct
69 Correct 407 ms 110188 KB Output is correct
70 Correct 13 ms 74076 KB Output is correct
71 Correct 307 ms 103788 KB Output is correct
72 Correct 237 ms 97040 KB Output is correct
73 Correct 248 ms 101392 KB Output is correct
74 Correct 280 ms 97180 KB Output is correct
75 Correct 1089 ms 244044 KB Output is correct
76 Correct 692 ms 197280 KB Output is correct
77 Correct 719 ms 199776 KB Output is correct
78 Correct 1400 ms 246648 KB Output is correct
79 Correct 1915 ms 223392 KB Output is correct
80 Correct 1118 ms 187544 KB Output is correct
81 Correct 1623 ms 204608 KB Output is correct
82 Correct 1750 ms 190368 KB Output is correct
83 Correct 1747 ms 206768 KB Output is correct