Submission #620517

# Submission time Handle Problem Language Result Execution time Memory
620517 2022-08-03T06:43:41 Z Theo830 Rainy Markets (CCO22_day1problem2) C++17
5 / 25
705 ms 247496 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9+7;
const ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ii,ll>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
int main(void){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin>>n;
    ll b[n],p[n],u[n];
    ll b2[n];
    f(i,0,n){
        cin>>b[i];
        b2[i] = b[i];
    }
    f(i,0,n-1){
        cin>>p[i];
    }
    f(i,0,n-1){
        cin>>u[i];
    }
    bool ok = 1;
    f(i,0,n-1){
        ll posoi = max(0LL,p[i] - u[i]);
        ll vale = min(posoi,b2[i]);
        b2[i] -= vale;
        posoi -= vale;
        b2[i+1] -= posoi;
        if(b2[i+1] < 0){
            ok = 0;
        }
    }
    if(ok){
        cout<<"YES\n";
        vector<vector<ll> >a,um,c;
        vector<ll> A,UM,C;
        ll ans = 0;
        ll neo[n] = {0};
        ll arxiko[n];
        f(i,0,n){
            arxiko[i] = b[i];
        }
        f(i,0,n-1){
            ll vale = max(0LL,min(p[i],b[i]));
            p[i] -= vale;
            b[i] -= vale;
            A.pb(vale);
            neo[i] += vale;
            UM.pb(0);
            C.pb(p[i]);
            neo[i+1] += p[i];
            b[i+1] -= p[i];
            if(p[i] == 0){
                a.pb(A);
                um.pb(UM);
                c.pb(C);
                A.clear();
                UM.clear();
                C.clear();
            }
        }
        if(!A.empty()){
            a.pb(A);
            um.pb(UM);
            c.pb(C);
            A.clear();
            UM.clear();
            C.clear();
        }
        ll pos = 1;
        f(i,0,a.size()){
            ll sum = 0;
            ll pre = pos;
            f(j,0,(ll)a[i].size()){
                sum += max(0LL,neo[pos] - arxiko[pos]);
                pos++;
            }
            ans += sum;
            pos = pre;
            f(j,0,(ll)a[i].size()){
                ll posa = min({sum,u[pos-1],c[i][j]});
                um[i][j] = posa;
                c[i][j] -= posa;
                sum -= posa;
                pos++;
            }
            assert(sum == 0);
        }
        cout<<ans<<"\n";
        f(i,0,a.size()){
            f(j,0,(ll)a[i].size()){
                cout<<a[i][j]<<" "<<um[i][j]<<" "<<c[i][j]<<"\n";
            }
        }
    }
    else{
        cout<<"NO\n";
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:8:33: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define f(i,a,b) for(ll i = a;i < b;i++)
......
   91 |         f(i,0,a.size()){
      |           ~~~~~~~~~~~~           
Main.cpp:91:9: note: in expansion of macro 'f'
   91 |         f(i,0,a.size()){
      |         ^
Main.cpp:8:33: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define f(i,a,b) for(ll i = a;i < b;i++)
......
  110 |         f(i,0,a.size()){
      |           ~~~~~~~~~~~~           
Main.cpp:110:9: note: in expansion of macro 'f'
  110 |         f(i,0,a.size()){
      |         ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 210 ms 46824 KB Output is correct
5 Correct 273 ms 53020 KB Output is correct
6 Correct 207 ms 46512 KB Output is correct
7 Correct 315 ms 51964 KB Output is correct
8 Correct 4 ms 844 KB Output is correct
9 Correct 3 ms 852 KB Output is correct
10 Correct 548 ms 154908 KB Output is correct
11 Correct 461 ms 117388 KB Output is correct
12 Correct 563 ms 140568 KB Output is correct
13 Correct 705 ms 247496 KB Output is correct
14 Correct 257 ms 46148 KB Output is correct
15 Correct 524 ms 113020 KB Output is correct
16 Correct 537 ms 113892 KB Output is correct
17 Correct 500 ms 114088 KB Output is correct
18 Correct 487 ms 113884 KB Output is correct
19 Correct 522 ms 112952 KB Output is correct
20 Correct 516 ms 114784 KB Output is correct
21 Correct 512 ms 117656 KB Output is correct
22 Correct 622 ms 154892 KB Output is correct
23 Correct 511 ms 116120 KB Output is correct
24 Correct 554 ms 126568 KB Output is correct
25 Correct 261 ms 53100 KB Output is correct
26 Correct 279 ms 52348 KB Output is correct
27 Correct 512 ms 111264 KB Output is correct
28 Correct 629 ms 142336 KB Output is correct
29 Correct 591 ms 137476 KB Output is correct
30 Correct 599 ms 114944 KB Output is correct
31 Correct 598 ms 131780 KB Output is correct
32 Correct 503 ms 114408 KB Output is correct
33 Correct 267 ms 53200 KB Output is correct
34 Correct 265 ms 52972 KB Output is correct
35 Correct 265 ms 51868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 210 ms 46824 KB Output is correct
5 Correct 273 ms 53020 KB Output is correct
6 Correct 207 ms 46512 KB Output is correct
7 Correct 315 ms 51964 KB Output is correct
8 Correct 4 ms 844 KB Output is correct
9 Correct 3 ms 852 KB Output is correct
10 Correct 548 ms 154908 KB Output is correct
11 Correct 461 ms 117388 KB Output is correct
12 Correct 563 ms 140568 KB Output is correct
13 Correct 705 ms 247496 KB Output is correct
14 Correct 257 ms 46148 KB Output is correct
15 Correct 524 ms 113020 KB Output is correct
16 Correct 537 ms 113892 KB Output is correct
17 Correct 500 ms 114088 KB Output is correct
18 Correct 487 ms 113884 KB Output is correct
19 Correct 522 ms 112952 KB Output is correct
20 Correct 516 ms 114784 KB Output is correct
21 Correct 512 ms 117656 KB Output is correct
22 Correct 622 ms 154892 KB Output is correct
23 Correct 511 ms 116120 KB Output is correct
24 Correct 554 ms 126568 KB Output is correct
25 Correct 261 ms 53100 KB Output is correct
26 Correct 279 ms 52348 KB Output is correct
27 Correct 512 ms 111264 KB Output is correct
28 Correct 629 ms 142336 KB Output is correct
29 Correct 591 ms 137476 KB Output is correct
30 Correct 599 ms 114944 KB Output is correct
31 Correct 598 ms 131780 KB Output is correct
32 Correct 503 ms 114408 KB Output is correct
33 Correct 267 ms 53200 KB Output is correct
34 Correct 265 ms 52972 KB Output is correct
35 Correct 265 ms 51868 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Incorrect 0 ms 212 KB Output isn't correct
38 Halted 0 ms 0 KB -