我自己想到的ac代码

include

using namespace std;

int main()

{

int t;

cin>>t;

while(t--)

{

int m,a,b,c;

cin>>m>>a>>b>>c;

if(a>=m&&b>=m)

{

cout<<2m<

}

if(a

{

if(c>2m-a-b)

{

cout<<2m<

}

else{

cout<

}

}

if(a>=m&&b

{

if(c>=m-b)

{

cout<<2m<

}

else{

cout<

}

}

if(b>=m&&a

{

if(c>=m-a)

{

cout<<2*m<

}

else{

cout<

}

}

}

}

虽然太过于复杂了一点,但是能写出来就很开心了。

ai教的ac代码

include

using namespace std;

int main()

{

int t;

cin>>t;

while(t--)

{

int m,a,b,c;

cin>>m>>a>>b>>c;

int used=min(a,m)+min(b,m);

int left=2*m-used;

cout<

}

}

思路1.先固定分配,再填剩余。

2.首先我们能固定的一定是a,b的位置。所以固定好a,b后看情况将剩下的c填入。