跳到正文

个人记录

32pts求条

lhwBobby约 3 分钟
原文
文章信息与版本

文章信息

发布
2026年10月4日
收录
2026年10月4日
更新
2026年11月20日
篇幅
约 3 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
using db = double;
const int N = 1e5 + 10;

signed main() {
    int g1;
    cin >> g1;
    while(g1--){
        int x,y;
        cin >> x >> y;
        if((x % 100 && x > 0) || (y % 100 && y > 0) || (x + y > 8700)){
            cout << -1 << endl;
            continue;
        }
        int maxn = -1;
        for(int a = 0;a <= 9;a++){
            for(int b = 0;b <= 9;b++){
                for(int c = 0;c <= 9;c++){
                    for(int d = 0;d <= 1;d++){
                        for(int e = 0;e <= 1;e++){
                            int r = a * 100ll + b * 200ll + c * 500ll + d * 500ll + e * 1000ll;
                            if(r != x) continue;
                            for(int f = 0;f <= 9 - a;f++){
                                for(int g = 0;g <= 9 - b;g++){
                                    for(int h = 0;h <= 9 - c;h++){
                                        int bb = f * 100ll + g * 200ll + h * 500ll + (1 - d) * 500ll + (1 - e) * 1000ll;
                                        if(bb == y){
                                            maxn = max(maxn,a + b + c + d + e);
                                            
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        cout << maxn;
        if(g1 != 0) cout << endl;
    }
    return 0;
}
原文