NOIP2025T1
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n,p[N];
ll m,ans;
const int N=1e5+10;
struct node{int x,y;}a[N];
bool cmp(node x,node y){return x.x+x.y==y.x+y.y?x.x<x.y:x.x+x.y<y.x+y.y;}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>a[i].x>>a[i].y;
sort(a+1,a+n+1,cmp);
for(int i=1;i<n;i++) p[i]=a[i+1].x;
sort(p+1,p+n);ll k=0;
for(int i=0;i<n;i++){
k+=p[i];if(k>m) break;
ans=max(ans,(m-k)/(a[1].x+a[1].y)*2+i+((m-k)%(a[1].x+a[1].y)>=a[1].x));
}
cout<<ans;
return 0;
} //AC100#include <bits/stdc++.h>
#define ll long long
#define N 25
using namespace std;
struct OP{
int a,b,c;
int pre;
}op[1<<24];
int n;
ll dp[1<<24]; //dp[S]:还没进包的物品集合是S
ll x[N],y[N];
ll dis(int i,int j) {
return (x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
}
ll DP(int S) {
if (S==0) return 0;
if (dp[S]>0) return dp[S];
int c=log2(S&(-S))+1; //这次我必拿c
int pre=S^(1<<(c-1));
dp[S]=DP(pre)+dis(0,c)*2; //单拿c
op[S]={0,c,-1,pre};
for (int d=1;d<=n;d++) {
if (d!=c && S&(1<<(d-1))) {
//同时拿cd
pre=S^((1<<(c-1))|(1<<(d-1)));
ll tmp=DP(pre)+dis(0,c)+dis(c,d)+dis(0,d);
if (dp[S]>tmp) {
dp[S]=tmp;
op[S]={0,c,d,pre};
}
}
}
return dp[S];
}
int main() {
cin>>x[0]>>y[0]>>n;
for (int i=1;i<=n;i++) {
cin>>x[i]>>y[i];
}
dp[0]=0;
cout<<DP((1<<n)-1)<<endl;
OP cur=op[(1<<n)-1];
while (1) {
cout<<cur.a<<" "<<cur.b<<" ";
if (cur.c!=-1) cout<<cur.c<<" ";
int p=cur.pre;
if (!p) break;
cur=op[p];
}
cout<<0<<endl;
return 0;
}