1 #include <iostream> 2 #include <vector> 3 4 using namespace std; 5 6 int main(){ 7 int m,sum = 0; 8 cin >> m ; 9 vector<int> c(m+1,0); 10 for(int i = 1; i <= m ; ++ i) {cin >> c[i];sum+=c[i];} 11 int x,y,firstPart = 0, secondPart = 0,firstIndex = 0, secondIndex =0; 12 cin >> x >> y; 13 for(firstIndex = 0,secondIndex = m+1;firstIndex < secondIndex;){ 14 if (firstPart < x) firstPart+=c[++firstIndex]; 15 if (secondPart < x) secondPart += c[--secondIndex]; 16 if( firstPart >= x && secondPart >= x ) break; 17 } 18 if(firstPart > y || secondPart > y) cout<<0<<endl; 19 else{ 20 if(firstIndex >= secondIndex) cout<<0<<endl; 21 else{ 22 if(sum - firstPart - secondPart > 2*(y-x)) cout<<0<<endl; 23 else{ 24 while(secondPart + c[secondIndex-1]<= y && (secondIndex-1) > firstIndex){ 25 secondIndex--; 26 secondPart+=c[secondIndex]; 27 } 28 if (secondIndex-1 <= firstIndex) cout<<secondIndex<<endl; 29 else{ 30 if(sum - secondPart > y) cout<<0<<endl; 31 else cout<<secondIndex<<endl; 32 } 33 } 34 } 35 } 36 }
Codeforces Round #207 (Div. 2) A. Group of Students
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章