tle on #25,前面有些点 2.8s 左右过。
#include<bits/stdc++.h>
#define ll long long
#define up(i,l,r) for(int i=l; i<=r; ++i)
#define dn(i,r,l) for(int i=r; i>=l; --i)
#define pii pair<int,int>
#define mp make_pair
using namespace std;
const int N=100005, M=5, T=N*(1<<M), bs1=3571, bs2=2777;
const int P1=998244853, P2=1000000009;
int n, m, pos, mx, nxt[N][1<<M], tot, cnt[T];
pii init[N][1<<M], sp[T]; bool bit[N][1<<M];
struct data {
int w, a[M];
bool operator<(const data &rhs) const { return w<rhs.w; }
} p[N];
bool check(int x) {
pos=0;
dn(i,n,1) {
while(pos<n&&p[pos+1].w+p[i].w<=x) {
++pos;
up(o,1,mx) ++cnt[nxt[pos][o]];
}
int ret=pos;
up(o,1,mx) if(bit[i][o]) ret-=cnt[nxt[i][o]]; else ret+=cnt[nxt[i][o]];
if(ret>0) {
up(j,1,pos) up(o,1,mx) --cnt[nxt[j][o]];
return 1;
}
}
up(i,1,pos) up(o,1,mx) --cnt[nxt[i][o]];
return 0;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m, mx=(1<<m)-1;
up(i,1,n) {
up(j,0,m-1) cin >> p[i].a[j];
sort(p[i].a,p[i].a+m);
cin >> p[i].w;
}
sort(p+1,p+1+n);
up(i,1,n) up(o,1,mx) {
up(j,0,m-1) if(o>>j&1) {
init[i][o].first =((ll)init[i][o].first *bs1%P1+p[i].a[j])%P1;
init[i][o].second=((ll)init[i][o].second*bs2%P2+p[i].a[j])%P2;
bit[i][o]^=1;
}
sp[++tot]=init[i][o];
}
sort(sp+1,sp+1+tot), tot=unique(sp+1,sp+1+tot)-sp-1;
up(i,1,n) up(o,1,mx) nxt[i][o]=lower_bound(sp+1,sp+1+tot,init[i][o])-sp;
if(!check(2e9)) { cout << -1; return 0; }
int l=0, r=2e9, Ans;
while(l<=r) {
int mid=((ll)l+r)/2;
if(check(mid)) Ans=mid, r=mid-1;
else l=mid+1;
}
cout << Ans;
return 0;
}