#include #include using namespace std;

int main() { int t, n; cin >> t >> n; int d[n]; for(int i=0; i<t; i++) { for(int j=0; j<n; j++) { cin >> d[j]; } sort(d, d+n); int cnt = 0; while(d[n-1] > 0) { if(d[n-1] >= 2) { cnt++; d[n-1] -= 2; } else if(d[n-2] > 0) { cnt += 2; d[n-1]--; d[n-2]--; } else { cnt = -1; break; } sort(d, d+n); } cout << cnt << endl; } return 0; }

飞机大战游戏最少按键次数算法实现 - C++代码详解

原文地址: https://www.cveoy.top/t/topic/lB1p 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录