제출 #1367195

#제출 시각아이디문제언어결과실행 시간메모리
1367195weedywelonIMO (EGOI25_imo)C++20
10 / 100
2388 ms4072 KiB
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <deque>
#include <map>
#include <chrono>
#include <random>
#include <bitset>
#include <tuple>
#define SZ(x) int(x.size())
#define FR(i,a,b) for(int i=(a);i<(b);++i)
#define FOR(i,n) FR(i,0,n)
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define A first
#define B second
#define mp(a,b) make_pair(a,b)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef unsigned __int128 U128;
typedef __int128 I128;
typedef std::pair<int,int> PII;
typedef std::pair<LL,LL> PLL;
using namespace std;

bool cmp(pair<PLL,vector<LL> > x, pair<PLL,vector<LL> > y){
	if (x.A.A!=y.A.A) return x.A.A>y.A.A;
	return x.A.B<y.A.B;
}

signed main(){
	FAST;
	LL n,m,k; cin>>n>>m>>k;
	
	vector<pair<PLL,vector<LL> > > a;
	a.resize(n);
	FOR(i,n){
		a[i].B.resize(m);
		LL sum=0;
		FOR(j,m){
			cin>>a[i].B[j];
			sum+=a[i].B[j];
		}
		sort(a[i].B.begin(),a[i].B.end());
		a[i].A.A=sum;
		a[i].A.B=i;
	}
	sort(a.begin(),a.end(),cmp);
	
	vector<LL> pref[n], suf[n];
	FOR(i,n){
		pref[i].resize(m+1);
		suf[i].resize(m+1);
		
		pref[i][0]=0;
		FOR(j,m){
			pref[i][j+1]=pref[i][j]+a[i].B[j];
		}
		for (int j=m-1; j>=0; j--){
			if (j==m-1) suf[i][j]=a[i].B[j];
			else suf[i][j]=suf[i][j+1]+a[i].B[j];
		}
		reverse(suf[i].begin(),suf[i].end());
	}
	
	/*FOR(i,n){
		FOR(j,m+1) cout<<pref[i][j]<<" ";
		cout<<"\n";
	}*/
	
	LL ans=0;
	FOR(x,n) FOR(y,x){
		LL tmp=1e18;
		bool tb=false;
		if (a[x].A.B>a[y].A.B) tb=true;
	
		FOR(i,m+1){
			LL cur=pref[x][i]+(m-i)*k;
			//cout<<"cur: "<<cur<<"\n";
			
			LL rev=0;
			if (tb) rev=lower_bound(suf[y].begin(), suf[y].end(), cur)-suf[y].begin();
			else rev=upper_bound(suf[y].begin(), suf[y].end(), cur)-suf[y].begin();
			tmp=min(tmp, i+rev);
		}
		ans+=tmp;
	}
	cout<<ans;
	return 0;
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…