Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <algorithm>
  2. #define MAXN 1000000
  3.  
  4. typedef long long ll;
  5.  
  6. ll need[MAXN];
  7.  
  8. void valuta(int N, int C[], int L[], int P[])
  9. {
  10.     for(int i=0; i<N; i++) P[i] = 0;
  11.     ll s=0, uranio=0;
  12.     for(int i=0; i<2*N; i++)
  13.     {
  14.         uranio+=(C[i%N]-L[i%N]);
  15.         if(uranio < 0)
  16.         {
  17.             s = i+1;
  18.             uranio = 0;
  19.         }
  20.     }
  21.     if(s >= N) return;
  22.  
  23.     need[s] = 0;
  24.     P[s] = 1;
  25.     for(int i=1; i<N; i++)
  26.     {
  27.         s = (s-1)%N;
  28.         need[s] = std::max((ll)0, L[s] - C[s] + need[(s+1)%N]);
  29.         if(need[s] == 0) P[s] = 1;
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement