QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#628773#9423. Gold MedaledhliiAC ✓0ms3608kbC++14995b2024-10-10 22:12:382024-10-10 22:12:38

Judging History

你现在查看的是最新测评结果

  • [2024-10-10 22:12:38]
  • 评测
  • 测评结果:AC
  • 用时:0ms
  • 内存:3608kb
  • [2024-10-10 22:12:38]
  • 提交

answer

#include <bits/stdc++.h>
#define NAME "b"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
const int N = 1000006;
const int MOD = 1000000007;

int testCase;
int n;
ll k, m;

bool cmp(ll a, ll b) {
	return (a % k) > (b % k);
}

void process() {
	ll ans = 0;
	cin >> n >> k;
	vector<ll> arr(n);
	for (int i = 0; i < n; i++) cin >> arr[i];
	cin >> m;
	sort(arr.begin(), arr.end(), cmp);
	for (int i = 0; i < n; i++) {
		ll t = (ll)k - arr[i] % (ll)k;
		if (t == k) t = 0;
		if (m - t >= 0) {
			arr[i] += t;
			m -= t;
		}
		else {
			arr[i] += m;
			m = 0;
		}
		if (i == n - 1) arr[i] += m;
		ans += (arr[i] / k);
	}
	cout << ans << "\n";
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen(NAME".inp", "r", stdin);
	freopen(NAME".out", "w", stdout);
#endif
	cin >> testCase;
	while (testCase--) process();
	return 0;
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3604kb

input:

2
3 10
239 141 526
6
2 1
300 100
1000

output:

91
1400

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

100
39 88
746 86884 628655 868 87506 46761498 3338 91952768 312 9712 5277106 2263554 246545 98849 91459 6 5506 4 17626 5984050 32079 10 7672277 8104250 62 8976 866448 1 4 62240996 93128 181 6 9 5 175665 9 7680943 81
239822
9 200383
53147 17 82509 3 617847780 418677763 5402536 16 38253558
79857
66 60...

output:

2734453
5390
65
0
66483181
44507
54
0
166366037
76709
114876519
0
13117
1427237708
12524
19426
0
35644
4
266
34841131
731790799
9
11
0
51508673
2
262191
175
6286240839
0
1045
293089
167116
4
141328
455003437
86185475
14
1963
11
491358
163
8970
3869760302
14424321
31849
560665
133717
6261
99
11983
23...

result:

ok 100 lines

Extra Test:

score: 0
Extra Test Passed