Submission #934279

# Submission time Handle Problem Language Result Execution time Memory
934279 2024-02-27T05:07:21 Z IUA_Hasin Snowball (JOI21_ho_t2) C++17
33 / 100
2500 ms 5676 KB
#include <bits/stdc++.h>
 
#define endl                                "\n"
#define finp                                for(int i=0; i<n; i++)
#define fknp                                for(int k=0; k<n; k++)
#define yeap                                cout<<"YES"<<endl
#define nope                                cout<<"NO"<<endl
#define inpintn                             int n; cin>>n
#define inpintarrn                          int arr[n]; for(int i=0; i<n; i++){cin>>arr[i];}
#define inpllarrn                           long long arr[n]; for(int i=0; i<n; i++){cin>>arr[i];}
#define ll                                  long long
 
using namespace std;
 
 
int main ()
{
    ll n, q;
    cin>>n>>q;
    ll arr[n];
    for(int i=0; i<n; i++){
        cin>>arr[i];
    }

    if(n==1){
        ll w[q];
        ll pref[q+1];
        pref[0] = 0;
        for(int i=0; i<q; i++){
            cin>>w[i];
            pref[i+1] = pref[i] +w[i];
        }
        ll mn = pref[0];
        ll mx = pref[0];
        for(int i=0; i<q+1; i++){
            mn = min(mn, pref[i]);
            mx = max(mx, pref[i]);
        }
        ll ans = 0;
        if(mn<0){
            ans = ans-mn;
        }

        if(mx>0){
            ans = ans+mx;
        }
        // for(int i=0; i<q+1;)
        // cout<<mn<<endl;
        // cout<<mx<<endl;
       
        cout<<ans<<endl;

    } else {
        ll dis[n-1];
        for(int i=0; i<n-1; i++){
            dis[i] = arr[i+1] - arr[i];
        }

        ll ans[n];
        for(int i=0; i<n; i++){
            ans[i] = 0;
        }

        ll pref[q+1];
        pref[0] = 0;
        ll tt = 1;
        ll w[q];
        while(tt<=q){
            cin>>w[tt-1];
            pref[tt] = pref[tt-1] + w[tt-1]; 


            tt++;
        }
        // cout<<endl;

        // for(int i=0; i<n-1; i++){
        //     cout << dis[i] << " ";
        // }
        // cout<<endl;
        // for(int i=0; i<=q; i++){
        //     cout << pref[i] << " ";
        // }
        // cout<<endl;


        ll a, b;
        for(int i=0; i<n-1; i++){
            a = 0;
            b = dis[i];
            ll l = 0;
            ll r = dis[i];
            for(int j=1; j<=q; j++){
                ll c = pref[j];
                if(c>0){
                    ll temp1 = a+c;
                    l = max(temp1, l);
                    l = min(l, r);
                } else if(c<0){
                    ll temp2 = b+c;
                    r = min(r, temp2);
                    r = max(l, r);
                }
                // cout << l << " " << r << endl;
            }
            // cout<<endl;
            ans[i] += l;
            ans[i+1] += dis[i]-r;
        }

        ll mn = pref[0];
        ll mx = pref[0];
        for(int i=0; i<q+1; i++){
            mn = min(mn, pref[i]);
            mx = max(mx, pref[i]);
        }
        if(mn<0){
            ans[0] = ans[0]-mn;
        }
        
        if(mx>0){
            ans[n-1] = ans[n-1]+mx;
        }

        // cout<<mn<<endl;
        // cout<<mx<<endl;

        for(int i=0; i<n; i++){
            cout<<ans[i]<<endl;
        }


    }

    




    
 
    return 0;
  
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 7 ms 348 KB Output is correct
5 Correct 7 ms 348 KB Output is correct
6 Correct 7 ms 348 KB Output is correct
7 Correct 7 ms 508 KB Output is correct
8 Correct 7 ms 544 KB Output is correct
9 Correct 8 ms 348 KB Output is correct
10 Correct 7 ms 348 KB Output is correct
11 Correct 5 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 436 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 8 ms 552 KB Output is correct
16 Correct 7 ms 544 KB Output is correct
17 Correct 7 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 3 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 7 ms 348 KB Output is correct
5 Correct 7 ms 348 KB Output is correct
6 Correct 7 ms 348 KB Output is correct
7 Correct 7 ms 508 KB Output is correct
8 Correct 7 ms 544 KB Output is correct
9 Correct 8 ms 348 KB Output is correct
10 Correct 7 ms 348 KB Output is correct
11 Correct 5 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 436 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 8 ms 552 KB Output is correct
16 Correct 7 ms 544 KB Output is correct
17 Correct 7 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 3 ms 348 KB Output is correct
20 Correct 63 ms 5676 KB Output is correct
21 Correct 73 ms 5460 KB Output is correct
22 Correct 232 ms 5204 KB Output is correct
23 Correct 1816 ms 5156 KB Output is correct
24 Execution timed out 2538 ms 5456 KB Time limit exceeded
25 Halted 0 ms 0 KB -