zoukankan      html  css  js  c++  java
  • Codeforces Round #207 (Div. 2) A. Group of Students

     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 }

  • 相关阅读:
    谢尔排序(缩小增量排序)
    折半插入排序
    插入排序
    选择排序
    冒泡排序
    ul+js模拟select+改进
    ul+js模拟select
    前端面试题
    js数组去重的三种常用方法总结
    使用PHP实现文件上传和多文件上传
  • 原文地址:https://www.cnblogs.com/xiongqiangcs/p/3377844.html
Copyright © 2011-2022 走看看