Workspace

Người dùng chillnhuwchichill

Từ

Giới thiệu

ʚ𐔌՞. .՞𐦯ɞ ˙∘

include <iostream>

include <algorithm>

using namespace std; signed main(){ ios_base::sync_with_stdio(0); cin.tie(NULL); int64_t q, n, s, x, c, t, a, b; string d; cin >> q; while (q–){ cin >> n >> s; d=”“, c=t=0; while (n–){ cin >> x; c+=(x==1), d+=to_string(x); } cout << d << endl; if (c<s){ cout << -1 << ‘\n’; continue; } if (c==s){ cout << 0 << ‘\n’; continue; } while (c!=s){ a=d.find(“1”), b=d.rfind(“1”); if (a<d.size()-b-1) t+=a+1, d=d.substr(a+1), c–; else t+=b+1, d=d.substr(0, d.size()-b-1), c–; cout << d << endl; } cout << t << ‘\n’; } return 0; }

Lịch sử xếp hạng