QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#632501 | #9450. Balloon Robot | ucup-team5062# | AC ✓ | 95ms | 9904kb | C++20 | 1.2kb | 2024-10-12 13:29:05 | 2024-10-14 16:41:29 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
long long Solve(long long N, long long M, long long P, vector<long long> S, vector<long long> A, vector<long long> B) {
for (int i = 0; i < P; i++) A[i] -= 1;
for (int i = 0; i < N; i++) S[i] -= 1;
// Step 1. Sorting
vector<long long> List;
for (int i = 0; i < P; i++) List.push_back((S[A[i]] - B[i] + 2000000000LL * M) % M);
sort(List.begin(), List.end());
// Step 2. Get Initial Answer
long long Sum = 0;
for (int i = 0; i < (int)List.size(); i++) Sum += List[i];
// Step 3. Solve
long long Answer = Sum;
for (int i = 0; i < (int)List.size(); i++) {
Sum += (i == 0 ? 0 : M);
Sum -= P * (List[i] - (i == 0 ? 0 : List[i - 1]));
Answer = min(Answer, Sum);
}
return Answer;
}
int main() {
int T; scanf("%d", &T);
for (int t = 1; t <= T; t++) {
long long N, M, P; scanf("%lld%lld%lld", &N, &M, &P);
vector<long long> S(N, 0);
vector<long long> A(P, 0);
vector<long long> B(P, 0);
for (int i = 0; i < N; i++) scanf("%lld", &S[i]);
for (int i = 0; i < P; i++) scanf("%lld%lld", &A[i], &B[i]);
// Output
printf("%lld\n", Solve(N, M, P, S, A, B));
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3792kb
input:
4 2 3 3 1 2 1 1 2 1 1 4 2 3 5 1 2 1 1 2 1 1 2 1 3 1 4 3 7 5 3 5 7 1 5 2 1 3 3 1 5 2 5 2 100 2 1 51 1 500 2 1000
output:
1 4 5 50
result:
ok 4 lines
Test #2:
score: 0
Accepted
time: 95ms
memory: 9904kb
input:
1004 22 9426 26 1165 5248 8331 9055 1161 7381 2188 7489 5131 8434 2166 3981 6302 7188 4858 856 7797 9129 7839 1676 25 9053 20 6 22 68 12 16 11 63 17 49 5 10 21 68 17 80 18 18 10 28 15 55 14 80 1 45 21 67 5 74 13 4 3 34 7 80 9 95 5 52 8 31 2 53 7 22 5 99 20 66 12 2 33 9526 92 558 7460 280 7952 5186 9...
output:
94067 360219 223074 30971 171844 312753 0 158169 294738 291604 115632 59327 221328 287851 30518 337118 181724 249419 66367 10347 208411 180496 287130 40736 264604 278208 33792 191523 111583 31867 21143 232153 149868 191831 238832 63626 258936 133059 105618 237774 53942 342921 275883 110295 149350 20...
result:
ok 1004 lines
Extra Test:
score: 0
Extra Test Passed