A传送
B传送
A Changing Volume
AC代码
#include <bits/stdc++.h>
using namespace std;
int t;
int a, b;
int main() {
int t;
scanf("%d", &t);
while(t --) {
scanf("%d%d", &a, &b);
int t = abs(b - a);
int cnt = t / 5;
t -= cnt * 5;
if(t == 3 || t == 4) cout << cnt + 2 << '\n';
else if(t == 2 || t == 1) cout << cnt + 1 << '\n';
else cout << cnt << '\n';
}
return 0;
}
B Fridge Lockers
AC代码
#include <bits/stdc++.h>
using namespace std;
void Solve() {
int n, m;
cin >> n >> m;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
if (m < n || n == 2) {
cout << "-1\n";
return;
} else {
cout << 2 * accumulate(a.begin(), a.end(), 0) << '\n';
for (int i = 1; i <= n; i++) {
if (i == n)
cout << n << " " << 1 << '\n';
else
cout << i << " " << i + 1 << '\n';
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t = 1;
cin >> t;
while (t--) {
Solve();
}
return 0;
}