Codeforces Round #244 (Div. 2) A. Police Recruits
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
int n , x , crime=0, police=0 , i , tmp;
while(cin >> n)
{
crime=0;
police=0;
tmp=0;
for(i=0; i<n; i++)
{
cin >> x;
if(x > 0)
{
crime+=tmp;
tmp=0;
police+=x;
}
else
{
tmp++;
if(police >= tmp)
{
police = police - tmp;
tmp=0;
}
}
}
cout << tmp+crime << "\n";
}
return 0;
}
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
int n , x , crime=0, police=0 , i , tmp;
while(cin >> n)
{
crime=0;
police=0;
tmp=0;
for(i=0; i<n; i++)
{
cin >> x;
if(x > 0)
{
crime+=tmp;
tmp=0;
police+=x;
}
else
{
tmp++;
if(police >= tmp)
{
police = police - tmp;
tmp=0;
}
}
}
cout << tmp+crime << "\n";
}
return 0;
}
Comments
Post a Comment