Skip to content

L2-017 人以群分

Statement

Metadata

  • 作者: 陈越
  • 单位: 浙江大学
  • 代码长度限制: 16 KB
  • 时间限制: 150 ms
  • 内存限制: 64 MB

社交网络中我们给每个人定义了一个“活跃度”,现希望根据这个指标把人群分为两大类,即外向型(outgoing,即活跃度高的)和内向型(introverted,即活跃度低的)。要求两类人群的规模尽可能接近,而他们的总活跃度差距尽可能拉开。

输入格式

输入第一行给出一个正整数N2 \le N \le 10^5)。随后一行给出N个正整数,分别是每个人的活跃度,其间以空格分隔。题目保证这些数字以及它们的和都不会超过2^{31}

输出格式

按下列格式输出:

Outgoing #: N1
Introverted #: N2
Diff = N3

其中N1是外向型人的个数;N2是内向型人的个数;N3是两群人总活跃度之差的绝对值。

输入样例1

10
23 8 10 99 46 2333 46 1 666 555

输出样例1

Outgoing #: 5
Introverted #: 5
Diff = 3611

输入样例2

13
110 79 218 69 3721 100 29 135 2 6 13 5188 85

输出样例2

Outgoing #: 7
Introverted #: 6
Diff = 9359

Solution

#include <ctype.h>
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const double PI = 3.14159265358979323846264338327;
const double E = exp(1);
const double eps = 1e-6;

const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
const int MOD = 1e9 + 7;

int arr[maxn];

bool comp(int x, int y) {
    return x > y;
}

int main() {
    int n;
    scanf("%d", &n);
    int sum = 0;
    for (int i = 0; i < n; i++) {
        scanf("%d", &arr[i]);
        sum += arr[i];
    }
    sort(arr, arr + n, comp);
    int ans = n / 2;
    if (n % 2)
        ans++;
    int vis = 0;
    for (int i = 0; i < ans; i++) vis += arr[i];
    printf("Outgoing #: %d\n", ans);
    printf("Introverted #: %d\n", n - ans);
    printf("Diff = %d\n", 2 * vis - sum);
}

Last update: May 4, 2022
Back to top