社交网络中我们给每个人定义了一个“活跃度”,现希望根据这个指标把人群分为两大类,即外向型(outgoing,即活跃度高的)和内向型(introverted,即活跃度低的)。要求两类人群的规模尽可能接近,而他们的总活跃度差距尽可能拉开。
输入格式:
输入第一行给出一个正整数N(2≤N≤
1
0
5
10^5
105 )。随后一行给出N个正整数,分别是每个人的活跃度,其间以空格分隔。题目保证这些数字以及它们的和都不会超过
2
31
2^{31}
231
输出格式:
按下列格式输出:
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
一开始以为是二分,然后感觉是简单的贪心,两个阵营人数的最大差值是1,分情况讨论就行。
注意:
是make_pair(x,y) ,不要再加{}
/*
A: 10min
B: 20min
C: 30min
D: 40min
*/
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <sstream>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define mem(f, x) memset(f,x,sizeof(f))
#define fo(i,a,n) for(int i=(a);i<=(n);++i)
#define fo_(i,a,n) for(int i=(a);i<(n);++i)
#define debug(x) cout<<#x<<":"<<x<<endl;
#define endl '\n'
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
template<typename T>
ostream& operator<<(ostream& os,const vector<T>&v){for(int i=0,j=0;i<v.size();i++,j++)if(j>=5){j=0;puts("");}else os<<v[i]<<" ";return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>&v){for(auto c:v)os<<c<<" ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>&v){for(auto c:v)os<<c.first<<" "<<c.second<<endl;return os;}
template<typename T>inline void rd(T &a) {
char c = getchar(); T x = 0, f = 1; while (!isdigit(c)) {if (c == '-')f = -1; c = getchar();}
while (isdigit(c)) {x = (x << 1) + (x << 3) + c - '0'; c = getchar();} a = f * x;
}
typedef pair<int,int>PII;
typedef pair<long,long>PLL;
typedef long long ll;
typedef unsigned long long ull;
const int N=510,M=10010;
ll n,m,_;
void solve(){
cin>>n;
vector<int>A(n);
for(auto &c:A){
cin>>c;
}
sort(all(A));
int ans=0;
pair<int,int>res;
if(n&1){
int a,b;
a=b=0;
for(int i=0;i<n/2;i++)a+=A[i];
for(int i=n/2;i<n;i++)b+=A[i];
ans=max(ans,b-a);
res=make_pair(n/2,n-n/2);
a=b=0;
for(int i=0;i<=n/2;i++)a+=A[i];
for(int i=n/2+1;i<n;i++)b+=A[i];
if(b-a>ans){
ans=max(ans,b-a);
res=make_pair(n/2+1,n-n/2+1);
}
}
else{
int a=0;
for(int i=0,j=n-1;i<j;i++,j--)a+=A[j]-A[i];
ans=max(ans,a);
res=make_pair(n/2,n/2);
}
cout<<"Outgoing #: "<<res.second<<endl;
cout<<"Introverted #: "<<res.first<<endl;
cout<<"Diff = "<<ans<<endl;
}
int main(){
solve();
return 0;
}