//include //------------------------------------------ #include using namespace std; //typedef //------------------------------------------ using LL = int64_t; using VL = vector; using VVL = vector; using VS = vector; using PLL = pair; //container util //------------------------------------------ #define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) #define rwhole(f,x,...) ([&](decltype((x)) whole) { return (f)(rbegin(whole), rend(whole), ## __VA_ARGS__); })(x) #define EACH(i,c) for(decltype((c).begin()) i=(c).begin(); i!=(c).end(); ++i) #define EXIST(s,e) ((s).find(e)!=(s).end()) #define SORT(c) whole(sort, c) #define RSORT(c) rwhole(sort, c) //constant //-------------------------------------------- constexpr double EPS = 1e-10; constexpr double PI = M_PI; constexpr int MOD = 1000000007; // grid //-------------------------------------------- VL dx = {0, 1, 0, -1}; VL dy = {1, 0, -1, 0}; VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1}; VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1}; //debug //-------------------------------------------- #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; //IO accelerate //-------------------------------------------- struct InitIO { InitIO() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(30); } } init_io; //template //-------------------------------------------- // declaretion template istream& operator >>(istream& is, vector& vec); template ostream& operator <<(ostream& os, const pair& p); template ostream& operator <<(ostream& os, const vector& vec); template ostream& operator <<(ostream& os, const vector>& vv); template vector make_v(size_t a); template auto make_v(size_t a,Ts... ts); template typename enable_if::value==0>::type fill_v(T &t,const V &v); template typename enable_if::value!=0>::type fill_v(T &t,const V &v); // implementation template istream& operator >>(istream& is, vector& vec) { for(T& x: vec) is >> x; return is; } template ostream& operator <<(ostream& os, const pair& p) { os << p.first << "," << p.second; return os; } template ostream& operator <<(ostream& os, const vector& vec) { for(int i=0; i ostream& operator <<(ostream& s, const vector>& vv) { for (int i = 0; i < vv.size(); ++i) { s << vv[i] << endl; } return s; } // 多重vector // auto dp=make_v(4,h,w) みたいに使える template vector make_v(size_t a){return vector(a);} template auto make_v(size_t a,Ts... ts){ return vector(ts...))>(a,make_v(ts...)); } // 多重vectorのためのfill // fill_v(dp,0) みたいに使える template typename enable_if::value==0>::type fill_v(T &t,const V &v){t=v;} template typename enable_if::value!=0>::type fill_v(T &t,const V &v){ for(auto &e:t) fill_v(e,v); } template void chmax(T&a,U b){if(a void chmin(T&a,U b){if(b T gcd(T a, T b) { return b?gcd(b,a%b):a;} template T lcm(T a, T b) { return a/gcd(a,b)*b;} //main code int main(int argc, char *argv[]) { LL n,k; cin >> n >> k; VL a(n); cin >>a; k--; if (a[k] == 0) { cout << 0 << endl; return 0; } int l = 0, r = n-1; for (int i = 0; i < k; i++) { if (a[i] == 0) { l = i+1; } if (a[i] == 1) { l = i; } } for (int i = k+1; i < n; i++) { if (a[i] == 0) { r = i-1; break; } if (a[i] == 1) { r = i; break; } } if (a[k] == 1) { LL sl = 0, sr = 0; for (int i = l; i <= k; i++) { sl += a[i]; } for (int i = k; i <= r; i++) { sr += a[i]; } cout << max(sl, sr) << endl; } else { LL ans = 0; for (int i = l; i <= r; i++) { ans += a[i]; } cout << ans << endl; } return 0; }