题解:CF2137C Maximum Even Sum
CF2137C 题解
题意
给定两个数 -1。
思路
显然可以分类讨论。
对于最简单的情况,
若 -1。
若 -1。如果
若
代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int t;
cin>>t;
while(t--){
int a,b;
cin>>a>>b;
if(a%2==0&&b%2==1){
cout<<-1<<endl;
continue;
}
else if(a%2==0&&b%2==0){
cout<<a*(b/2)+2<<endl;
}
else if(a%2==1&&b%2==1){
cout<<a*b+1<<endl;
}
else{
if(b%4!=0){
cout<<-1<<endl;
}
else{
cout<<a*(b/2)+2<<endl;
}
}
}
return 0;
}