p1m2

ps:就一个普通的二分。。。永远都是debug的时间比写代码的时间还长

#pragma warning(disable:4996)
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define P pair<int, int>
#define pb push_back
#define mp make_pair
#define pp pop_back
#define lson root << 1
#define INF (int)2e9 + 7
#define rson root << 1 | 1
#define LINF (unsigned long long int)1e18
#define sc(x) scanf("%d", &x)
#define pr(x) printf("%d\n", x)
#define mem(arry, in) memset(arry, in, sizeof(arry))
using namespace std;

inline void upd(int &x, int y) { x < y && (x = y); }

const int N = 300005;

int T, n;
int a[N];

bool check(int mid) {
    ll res = 0;
    for (int i = 1; i <= n; ++i) {
        if (a[i] - mid == 1 || a[i] - mid == 0) continue;
        if (a[i] < mid) res += -2 * 1ll * (mid - a[i]);
        else if (a[i] > mid) res += (ll)((a[i] - mid) / 2) * 2;
    }
    return res >= 0;
}

int main()
{
    sc(T);
    while (T--) {
        sc(n);
        for (int i = 1; i <= n; ++i) sc(a[i]);
        int l = 0, r = 100000000;
        int ans = -1;
        for (int i = 1; i <= 50; ++i) {
            int mid = (l + r) >> 1;
            if (check(mid)) {
                ans = mid;
                l = mid + 1;
            }
            else r = mid;
        }
        cout << ans << endl;
    }
    return 0;
}

 

posted @ 2018-08-14 12:52  天之道,利而不害  阅读(223)  评论(0编辑  收藏  举报