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 }

  • 相关阅读:
    敲七
    二维指针数组**p
    食物链(待解决)
    蛇行矩阵
    快速排序 QuickSort
    堆排序
    猪的安家
    百度语言翻译机
    HTML <base> 标签
    免费网络管理流量监控软件大比拼
  • 原文地址:https://www.cnblogs.com/xiongqiangcs/p/3377844.html
Copyright © 2011-2022 走看看