답안 #638766

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
638766 2022-09-07T11:23:58 Z morasha3 Rainy Markets (CCO22_day1problem2) C++17
5 / 25
476 ms 98592 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef   double ld;
const ll mod=1e9+7;
#define endl '\n'

int32_t main()
{
    //freopen("jumping.in","r",stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    ll arr[n],a[n];
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
        a[i]=arr[i];
    }
    vector<ll>v,b;
    for(int i=0; i<n-1; i++)
    {
        ll x;
        cin>>x;
        v.push_back(x);
    }

    for(int i=0; i<n-1; i++)
    {
        ll x;
        cin>>x;
        b.push_back(x);
    }
    bool f=1;
    ll cnt=0;
    for(int i=0; i<n-1; i++)
    {
        ll o=v[i];
        o-=arr[i]-cnt;
        cnt=0;
        if(o>0)
        {
            o-=b[i];
            if(o>0)
            {
                ll u=o;
                o-=arr[i+1];
                if(o>0)
                {
                    f=0;
                    break;
                }
                cnt=u;
            }
        }
    }
    if(f==0)
    {
        cout<<"NO";
    }
    else
    {
        cnt=0;
        ll ans=0;
        cout<<"YES"<<endl;
        cnt=0;
        ll ans1[n-1],ans2[n-1],ans3[n-1];
        for(int i=0; i<n-1; i++)
        {
            ll o=v[i];
            o-=arr[i];
            ans1[i]=(min(arr[i],v[i]));
            arr[i]-=min(arr[i],v[i]);
            if(o>0)
            {
                v[i]=o;
                o-=b[i];
                ans2[i]=(min(b[i],v[i]));
                if(o>0)
                {
                    v[i]=o;
                    ans3[i]=(v[i]);
                    arr[i+1]-=v[i];
                }
                else
                    ans3[i]=(0);
            }
            else
            {
                ans2[i]=(0);
                ans3[i]=(0);
            }
        }
        for(int i=0; i<n-1; i++)
        {
            if(arr[i]>0)
            {
                ll o=min(ans2[i],arr[i]);
                ans2[i]-=o;
                ans1[i]+=o;
                if(arr[i]>0)
                {
                    ll o=min(arr[i+1]+arr[i],a[i+1]);
                    o=o-arr[i+1];
                    arr[i+1]+=o;
                    ll u=0;
                    if(i==0)
                    u=min({o,ans3[i],a[i]-ans1[i]});
                    else u=min({o,ans3[i],(a[i]-ans3[i-1])-ans1[i]});
                    ans1[i]+=u;
                    ans3[i]-=u;
                    arr[i]-=o;

                }
            }
        }
        for(int i=n-2; i>=0; i--)
        {
            if(arr[i+1]>0)
            {
                ll o=min(ans2[i],arr[i+1]);
                ans2[i]-=o;
                ans3[i]+=o;
                arr[i+1]-=o;
                if(arr[i+1]>0)
                {
                    o=min(arr[i]+arr[i+1],a[i]);
                    o=o-arr[i];
                    arr[i]+=o;
                    ll u=0;
                    if(i!=n-2)
                     u=min({o,ans1[i],(a[i+1]-ans1[i+1])-ans3[i]});
                    else  u=min({o,ans1[i],(a[i+1])-ans3[i]});
                    ans3[i]+=u;
                    ans1[i]-=u;
                }
            }
        }
        for(int i=0; i<n-1; i++)
        {
            ans+=ans2[i];
        }
        cout<<ans<<endl;
        for(int i=0; i<n-1; i++)
        {
            cout<<ans1[i]<<" "<<ans2[i]<<" "<<ans3[i]<<endl;
        }
    }


    return 0;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 195 ms 36012 KB Output is correct
5 Correct 226 ms 36032 KB Output is correct
6 Correct 192 ms 36032 KB Output is correct
7 Correct 236 ms 36032 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 347 ms 67608 KB Output is correct
11 Correct 358 ms 70828 KB Output is correct
12 Correct 462 ms 96732 KB Output is correct
13 Correct 476 ms 95668 KB Output is correct
14 Correct 200 ms 50348 KB Output is correct
15 Correct 472 ms 98452 KB Output is correct
16 Correct 462 ms 98592 KB Output is correct
17 Correct 456 ms 98448 KB Output is correct
18 Correct 460 ms 98464 KB Output is correct
19 Correct 459 ms 98444 KB Output is correct
20 Correct 456 ms 98384 KB Output is correct
21 Correct 453 ms 98296 KB Output is correct
22 Correct 463 ms 96032 KB Output is correct
23 Correct 469 ms 98460 KB Output is correct
24 Correct 456 ms 97780 KB Output is correct
25 Correct 241 ms 56956 KB Output is correct
26 Correct 243 ms 56880 KB Output is correct
27 Correct 452 ms 98572 KB Output is correct
28 Correct 465 ms 96752 KB Output is correct
29 Correct 455 ms 98496 KB Output is correct
30 Correct 472 ms 98576 KB Output is correct
31 Correct 470 ms 97368 KB Output is correct
32 Correct 464 ms 98492 KB Output is correct
33 Correct 247 ms 56880 KB Output is correct
34 Correct 243 ms 56860 KB Output is correct
35 Correct 246 ms 56868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Incorrect 1 ms 468 KB Integer -14 violates the range [0, 113]
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Incorrect 1 ms 468 KB Integer -14 violates the range [0, 113]
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 195 ms 36012 KB Output is correct
5 Correct 226 ms 36032 KB Output is correct
6 Correct 192 ms 36032 KB Output is correct
7 Correct 236 ms 36032 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 347 ms 67608 KB Output is correct
11 Correct 358 ms 70828 KB Output is correct
12 Correct 462 ms 96732 KB Output is correct
13 Correct 476 ms 95668 KB Output is correct
14 Correct 200 ms 50348 KB Output is correct
15 Correct 472 ms 98452 KB Output is correct
16 Correct 462 ms 98592 KB Output is correct
17 Correct 456 ms 98448 KB Output is correct
18 Correct 460 ms 98464 KB Output is correct
19 Correct 459 ms 98444 KB Output is correct
20 Correct 456 ms 98384 KB Output is correct
21 Correct 453 ms 98296 KB Output is correct
22 Correct 463 ms 96032 KB Output is correct
23 Correct 469 ms 98460 KB Output is correct
24 Correct 456 ms 97780 KB Output is correct
25 Correct 241 ms 56956 KB Output is correct
26 Correct 243 ms 56880 KB Output is correct
27 Correct 452 ms 98572 KB Output is correct
28 Correct 465 ms 96752 KB Output is correct
29 Correct 455 ms 98496 KB Output is correct
30 Correct 472 ms 98576 KB Output is correct
31 Correct 470 ms 97368 KB Output is correct
32 Correct 464 ms 98492 KB Output is correct
33 Correct 247 ms 56880 KB Output is correct
34 Correct 243 ms 56860 KB Output is correct
35 Correct 246 ms 56868 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Incorrect 1 ms 468 KB Integer -14 violates the range [0, 113]
45 Halted 0 ms 0 KB -