Submission #620517

#TimeUsernameProblemLanguageResultExecution timeMemory
620517Theo830Rainy Markets (CCO22_day1problem2)C++17
5 / 25
705 ms247496 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...