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
相關文章
- Codeforces Round #242 (Div. 2) A. Squats
- Codeforces Round #213 (Div. 2) A. Good NumberGo
- Codeforces Round #243 (Div. 2) A. Sereja and Mugs
- Codeforces Round #253 (Div. 2) A. Anton and Letters
- Codeforces Round #250 (Div. 2) A. The Child and Homework
- Codeforces Round #244 (Div. 2) A. Police RecruitsUI
- Codeforces Round #249 (Div. 2) A. Black Square
- Codeforces Round #246 (Div. 2) A. Choosing Teams
- Codeforces Round #216 (Div. 2)A. Valera and Plates
- Codeforces Round #209 (Div. 2) A. Table
- Codeforces Round #210 (Div. 2) A. Levko and Table
- Codeforces Round #192 (Div. 2) A. Cakeminator
- Codeforces Round #189 (Div. 2) A. Magic Numbers
- Codeforces Round #228 (Div. 2) A. Fox and Number GameGAM
- Codeforces Round #215 (Div. 2) A. Sereja and Coat Rack
- Codeforces Round #248 (Div. 2) A. Kitahara Haruki's Gift
- Codeforces Round #235 (Div. 2) A. Vanya and Cards
- Codeforces Round #195 (Div. 2) A. Vasily the Bear and Triangle
- Codeforces Round #206 (Div. 2) A. Vasya and Digital RootGit
- Codeforces Beta Round #76 (Div. 1 Only) A. Frames
- (Codeforces Round #136 (Div. 2))A. Little Elephant and Function(遞迴分析,簡單)Function遞迴
- Codeforces Round #207 (Div. 2)C. Knight Tournament(SET也可以搞定)
- Codeforces Round #639 (Div. 2)
- Codeforces Round #541 (Div. 2)
- Codeforces Round #682 (Div. 2)
- Codeforces Round #678 (Div. 2)
- Codeforces Round #747 (Div. 2)
- Codeforces Round #673 (Div. 2)
- Codeforces Round #672 (Div. 2)
- Codeforces Round #448 (Div. 2) A
- Codeforces Round #217 (Div. 2)
- Codeforces Round #256 (Div. 2)
- Codeforces Round #259 (Div. 2)
- Codeforces Round #257 (Div. 2)
- Codeforces Round #258 (Div. 2)
- Codeforces Round #171 (Div. 2)
- Codeforces Round #173 (Div. 2)
- Codeforces Round 951 (Div. 2)