3626. 三元一次方程 - AcWing题库
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, flag = 0;
cin >> n;
for (int i = 0; i <= n; i ++ ) {
for (int j = 0; j <= n; j ++ ) {
for (int k = 0; k <= n; k ++ ) {
if (3 * i + 5 * j + 7 * k == n) {
cout << i << " " << j << " " << k << endl;
flag = 1;
break;
}
if (i == n && j == n && k == n) {
cout << "-1" << endl;
break;
}
}
if (flag)
break;
}
if (flag)
break;
}
}
}
?3627. 最大差值 - AcWing题库
必须long long,acwing的测评真离谱
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
long long a[200010];
int main() {
int t;
cin >> t;
while(t--){
int n,k;
cin >> n >> k;
for (int i = 0; i < n; i ++ ) cin >> a[i];
sort(a,a+n);
long long sum=0;
for(int i=n-1;i>=n-1-k;i--){
sum+=a[i];
}
cout << sum << endl;
}
}
?
|