msiamn

Codeforces 680B

Jun 8th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.08 KB | None | 0 0
  1. /*******************************************************************************\
  2. |*********S***   ******  *************  *************  **************  *  ******|
  3. |***********   ********  ************    ************    ***********  **  ******|
  4. |*********   **********  ***********  *** ***********  *  *********  ***  ******|
  5. |********   ***********  *I********  ****  **********  ***  *****  *****  ******|
  6. |********   ***********  *********  ******  *********  *****  **  ******  ******|
  7. |**********   *********  ********  ***A****  ********  *******  ********  ******|
  8. |***********   ********  *******  **********  *******  *****************  ******|
  9. |**********   *********  ******  ************  ******  *****************  ******|
  10. |********   ***********  *****  **************  *****  ********M********  ******|
  11. |*****   **************  ****  ****************  ****  *****************  ******|
  12. |*******************************************************************************|
  13. |**************BSMRSTU********************************CSE***********************|
  14. \*******************************************************************************/
  15. #include<bits/stdc++.h>
  16. #define ll long long
  17. #define B break
  18. #define C continue
  19. #define sf scanf
  20. #define pf printf
  21. #define byebye return 0
  22. using namespace std;
  23. int main()
  24. {
  25.     int n,a,i,j,k,t=0;
  26.     cin>>n>>a;
  27.     a--;
  28.     int c[n];
  29.     for(i=0; i<n; i++)
  30.     {
  31.         cin>>c[i];
  32.     }
  33.     if(c[a]==1)t++;
  34.     if((a)<=(n/2))
  35.     {
  36.         for(i=a-1,j=a+1; i>=0, j<n; i--,j++)
  37.         {
  38.             if(c[i]==1 && c[j]==1)
  39.                 t+=2;
  40.             if(i==-1 && j>2*a)
  41.             {
  42.                 for(k=j; k<n; k++)
  43.                 {
  44.                     if(c[k]==1)t++;
  45.                 }
  46.                 break;
  47.             }
  48.         }
  49.     }
  50.     else if(a>(n/2))
  51.     {
  52.         for(i=a-1,j=a+1; i>=0, j<n; i--,j++)
  53.         {
  54.             if(c[i]==1 && c[j]==1)
  55.                 t+=2;
  56.         }
  57.         for(i=((2*a)-n); i>=0; i--)
  58.         {
  59.             if(c[i]==1)t++;
  60.         }
  61.     }
  62.     cout<<t;
  63.     byebye;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment