#include<bits/stdc++.h>
#define ll long long
#define maxn 30
using namespace std;
ll read(){
ll f=1,k=0;
char c=0;
while(c<'0'||c>'9'){
if(c=='-')f=-1;
c=getchar();
}
while(c>='0'&&c<='9'){
k=k*10+c-'0';
c=getchar();
}
return k*f;
}
void out(ll x){
if(x<0){
x=-x;
putchar('-');
}
if(x>=10)out(x/10);
putchar(x%10+'0');
}
ll n,w[maxn],d[maxn],lj[maxn][maxn],lsw[maxn],lslj[maxn][maxn];
ll chkmin(ll a,ll b){
return(a<b?a:b);
}
bool check(ll x){
for(ll i=1;i<=n;i++){
lsw[x]+=lslj[x][i];
lslj[x][i]=0;
lslj[i][x]=0;
}
for(ll i=1;i<=n;i++){
if(lsw[i]>lsw[x])return 0;
}
for(ll i=1;i<=n;i++){
if(i==x)continue;
for(ll j=1;j<=n;j++){
ll d=lsw[x]-lsw[i],add=chkmin(d,lslj[i][j]);
lsw[i]+=add;
lslj[i][j]-=add;
lslj[j][i]-=add;
}
}
for(ll i=1;i<=n;i++){
for(ll j=1;j<=n;j++){
cout<<lslj[i][j]<<' '<<x<<endl;
if(lslj[i][j])return 0;
}
}
return 1;
}
int main(){
n=read();
for(ll i=1;i<=n;i++){
w[i]=read();
d[i]=read();
}
for(ll i=1;i<=n;i++){
for(ll j=1;j<=n;j++){
lj[i][j]=read();
}
}
for(ll i=1;i<=n;i++){
for(ll j=1;j<=n;j++){
lsw[j]=w[j];
for(ll k=1;k<=n;k++){
lslj[j][k]=lj[j][k];
}
}
if(check(i)){
out(i);putchar(' ');
}
}
return 0;
}
WA两个点,谢谢大佬们了