您的位置:首页 > 其它

Codeforces Round #207 (Div. 2) A. Group of Students

2013-10-19 14:29 447 查看
#include <iostream>
#include <vector>

using namespace std;

int main(){
int m,sum = 0;
cin >> m ;
vector<int> c(m+1,0);
for(int i = 1; i <= m ; ++ i) {cin >> c[i];sum+=c[i];}
int x,y,firstPart = 0, secondPart = 0,firstIndex = 0, secondIndex =0;
cin >>  x >>  y;
for(firstIndex = 0,secondIndex = m+1;firstIndex < secondIndex;){
if (firstPart < x) firstPart+=c[++firstIndex];
if (secondPart < x) secondPart += c[--secondIndex];
if( firstPart >= x && secondPart >= x ) break;
}
if(firstPart > y || secondPart > y) cout<<0<<endl;
else{
if(firstIndex >= secondIndex) cout<<0<<endl;
else{
if(sum - firstPart - secondPart > 2*(y-x)) cout<<0<<endl;
else{
while(secondPart + c[secondIndex-1]<= y && (secondIndex-1) > firstIndex){
secondIndex--;
secondPart+=c[secondIndex];
}
if (secondIndex-1 <= firstIndex) cout<<secondIndex<<endl;
else{
if(sum - secondPart > y) cout<<0<<endl;
else cout<<secondIndex<<endl;
}
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: