Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- template <typename A, typename B>
- string to_string(pair<A, B> p);
- template <typename A, typename B, typename C>
- string to_string(tuple<A, B, C> p);
- template <typename A, typename B, typename C, typename D>
- string to_string(tuple<A, B, C, D> p);
- string to_string(const string& s) {
- return '"' + s + '"';
- }
- string to_string(const char* s) {
- return to_string((string) s);
- }
- string to_string(bool b) {
- return (b ? "true" : "false");
- }
- string to_string(const char &ch) {
- return string(1, ch);
- }
- string to_string(vector<bool> v) {
- bool first = true;
- string res = "{";
- for (int i = 0; i < static_cast<int>(v.size()); i++) {
- if (!first) {
- res += ", ";
- }
- first = false;
- res += to_string(v[i]);
- }
- res += "}";
- return res;
- }
- template <size_t N>
- string to_string(bitset<N> v) {
- string res = "";
- for (size_t i = 0; i < N; i++) {
- res += static_cast<char>('0' + v[i]);
- }
- return res;
- }
- template <typename A>
- string to_string(A v) {
- bool first = true;
- string res = "{";
- for (const auto &x : v) {
- if (!first) {
- res += ", ";
- }
- first = false;
- res += to_string(x);
- }
- res += "}";
- return res;
- }
- template <typename A, typename B>
- string to_string(pair<A, B> p) {
- return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
- }
- template <typename A, typename B, typename C>
- string to_string(tuple<A, B, C> p) {
- return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
- }
- template <typename A, typename B, typename C, typename D>
- string to_string(tuple<A, B, C, D> p) {
- return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
- }
- void debug_out() { cerr << endl; }
- template <typename Head, typename... Tail>
- void debug_out(Head H, Tail... T) {
- cerr << " " << to_string(H);
- debug_out(T...);
- }
- #ifdef LOCAL
- #define pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
- #else
- #define pr(...) 42
- #endif
- double tick(){
- static clock_t oldtick;
- clock_t newtick = clock();
- double diff = 1.0 * (newtick - oldtick) / CLOCKS_PER_SEC;
- oldtick = newtick;
- return diff;
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- cout << setprecision(10);
- cout << fixed;
- #ifdef LOCAL
- freopen("b_candy_love.in", "rt", stdin);
- #endif
- int tt, x;
- cin >> tt;
- while(tt--) {
- int n;
- cin >> n;
- vector <int> arr(n);
- for (int i = 0; i < n; i++) {
- cin >> arr[i];
- }
- cin >> x;
- vector <long long> cum1(n, 0);
- vector <long long> cum2(n, 0);
- cum1[0] = arr[0];
- for (int i = 1; i < n; i++) {
- cum1[i] = cum1[i - 1] + arr[i];
- }
- cum2[n - 1] = arr[n - 1];
- for (int i = n - 2; i >= 0; i--) {
- cum2[i] = cum2[i + 1] + arr[i];
- }
- if (n == 1) cout << 1 << " " << 0 << endl;
- else if (n == 2) cout << 1 << " " << 1 << endl;
- else {
- pair <int, int> ans = {1, 1};
- for (int i = 1; i < n - 1; i++) {
- long long tl = cum1[i - 1] / x;
- long long rl = cum2[i + 1];
- if (tl == rl) {
- if (cum1[i - 1] % x == 0) {
- ans.first = i + 1;
- ans.second = n - i - 1;
- } else {
- ans.first = i;
- ans.second = n - i;
- }
- break;
- }
- else if (tl < rl) {
- ans.first = i + 1;
- ans.second = n - i - 1;
- } else {
- ans.first = i;
- ans.second = n - i;
- break;
- }
- }
- cout << ans.first << " " << ans.second << endl;
- }
- }
- #ifdef LOCAL
- fprintf(stderr, "Time elapsed: %.12lf secs...\n", tick());
- #endif
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement