Submission #3201153


Source Code Expand

Copy
/*input
16 10
1 7 12 27 52 75 731 13856 395504 534840 1276551 2356789 9384806 19108104 82684732 535447408
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}
ll n,x;
ll a[maxn];
vector<ll> v;

ll cal(int i){
	ll cnt=0;
	for(ll d=0;d<n;d++){
		cnt+=a[d]*v[d/i];
	}
	return cnt+i*x;
}

int main()
{
	cin>>n>>x;
	v.pb(5);
	{
		ll meow=5;
		while(SZ(v)<n){	
			v.pb(meow);
			meow+=2;
		}
	}
	REP(i,n) cin>>a[i];

	sort(a,a+n,greater<ll>());

	ll l=1,r=n;
	ll ans;
	if(cal(l)<=cal(l+1)) ans=cal(l);
	else{
		while(l!=r-1){
			ll mid=(l+r)/2;
			if(cal(mid)<=cal(mid+1)) r=mid;
			else l=mid;
		}
		ans=cal(r);
	}
	cout<<ans+n*x<<'\n';
	return 0;
}

Submission Info

Submission Time
Task B - Garbage Collector
User iloveUtaha
Language C++14 (GCC 5.4.1)
Score 700
Code Size 2150 Byte
Status
Exec Time 151 ms
Memory 3440 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
Subtask1 400 / 400 sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, stest_01.txt, stest_02.txt, stest_03.txt, stest_04.txt, stest_05.txt, stest_06.txt, stest_07.txt, stest_08.txt, stest_09.txt, stest_10.txt, stest_11.txt, stest_12.txt
All 300 / 300 sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, stest_01.txt, stest_02.txt, stest_03.txt, stest_04.txt, stest_05.txt, stest_06.txt, stest_07.txt, stest_08.txt, stest_09.txt, stest_10.txt, stest_11.txt, stest_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt
Case Name Status Exec Time Memory
sample_01.txt 1 ms 256 KB
sample_02.txt 1 ms 256 KB
sample_03.txt 1 ms 256 KB
sample_04.txt 1 ms 256 KB
stest_01.txt 3 ms 256 KB
stest_02.txt 3 ms 256 KB
stest_03.txt 1 ms 256 KB
stest_04.txt 1 ms 256 KB
stest_05.txt 2 ms 256 KB
stest_06.txt 2 ms 256 KB
stest_07.txt 2 ms 256 KB
stest_08.txt 2 ms 256 KB
stest_09.txt 2 ms 256 KB
stest_10.txt 2 ms 256 KB
stest_11.txt 2 ms 256 KB
stest_12.txt 1 ms 256 KB
test_13.txt 151 ms 3440 KB
test_14.txt 151 ms 3440 KB
test_15.txt 30 ms 1016 KB
test_16.txt 127 ms 3440 KB
test_17.txt 131 ms 3440 KB
test_18.txt 19 ms 892 KB
test_19.txt 136 ms 3440 KB
test_20.txt 139 ms 3440 KB
test_21.txt 139 ms 3440 KB
test_22.txt 135 ms 3440 KB
test_23.txt 127 ms 3440 KB
test_24.txt 131 ms 3440 KB
test_25.txt 65 ms 2036 KB
test_26.txt 139 ms 3440 KB
test_27.txt 139 ms 3440 KB
test_28.txt 109 ms 2928 KB