Advertisement
loaymahmoud

427A - Police Recruits

Dec 6th, 2023
732
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. #include <vector>
  4.  
  5. int main() {
  6.     int numberOfCases;
  7.     cin>>numberOfCases;
  8.     vector<int> cases(numberOfCases);
  9.    
  10.  
  11.     for(int i=0 ; i<numberOfCases ; i++) {
  12.         cin>>cases[i];
  13.     }
  14.     int pIndex=0;
  15.     for(int i=0 ; i<numberOfCases ; i++) {
  16.         if(cases[i]>0) {
  17.             pIndex=i;
  18.             break;
  19.         }
  20.     }
  21.  
  22.     for(int i=pIndex+1 ; i<numberOfCases ; i++) {
  23.        cases[i]+=cases[i-1];
  24.     }
  25.  
  26.     int neg=0;
  27.     for(int i=0 ; i<numberOfCases ; i++) {
  28.         if(cases[i]<0) {
  29.             neg++;
  30.         }
  31.     }
  32.     cout<<neg;
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement