Submission #71851523
Source Code Expand
#include<bits/stdc++.h>
#include<atcoder/modint>
typedef long long ll;
using namespace std;
using mint = atcoder::modint998244353;
int main(){
int n,m;
cin >> n >> m;
ll A[n], B[m];
for(int i = 0; i < n; i++) cin >> A[i];
for(int i = 0; i < m; i++) cin >> B[i];
sort(B, B+m);
ll C[m+1];
C[0] = 0;
for(int i = 0; i < m; i++) C[i+1] = C[i] + B[i];
mint ans = 0;
for(int i = 0; i < n; i++){
ll idx = lower_bound(B, B+m, A[i]) - B;
ans += idx * A[i];
ans -= C[idx];
ans += C[m] - C[idx];
ans -= (m-idx) * A[i];
}
cout << ans.val() << endl;
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Sum of Differences |
| User | sakimori_coder |
| Language | C++23 (GCC 15.2.0) |
| Score | 400 |
| Code Size | 661 Byte |
| Status | AC |
| Exec Time | 210 ms |
| Memory | 10684 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 400 / 400 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00-sample-01.txt, 00-sample-02.txt |
| All | 00-sample-01.txt, 00-sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00-sample-01.txt | AC | 1 ms | 3564 KiB |
| 00-sample-02.txt | AC | 1 ms | 3408 KiB |
| 01-01.txt | AC | 5 ms | 3728 KiB |
| 01-02.txt | AC | 4 ms | 3676 KiB |
| 01-03.txt | AC | 5 ms | 3744 KiB |
| 01-04.txt | AC | 4 ms | 3536 KiB |
| 01-05.txt | AC | 5 ms | 3820 KiB |
| 01-06.txt | AC | 4 ms | 3536 KiB |
| 01-07.txt | AC | 6 ms | 3612 KiB |
| 01-08.txt | AC | 5 ms | 3632 KiB |
| 01-09.txt | AC | 5 ms | 3572 KiB |
| 01-10.txt | AC | 4 ms | 3572 KiB |
| 01-11.txt | AC | 4 ms | 3632 KiB |
| 01-12.txt | AC | 4 ms | 3772 KiB |
| 01-13.txt | AC | 5 ms | 3536 KiB |
| 01-14.txt | AC | 5 ms | 3536 KiB |
| 01-15.txt | AC | 1 ms | 3500 KiB |
| 01-16.txt | AC | 1 ms | 3644 KiB |
| 01-17.txt | AC | 154 ms | 9304 KiB |
| 01-18.txt | AC | 160 ms | 8540 KiB |
| 01-19.txt | AC | 95 ms | 8300 KiB |
| 01-20.txt | AC | 78 ms | 5880 KiB |
| 01-21.txt | AC | 210 ms | 10584 KiB |
| 01-22.txt | AC | 167 ms | 10544 KiB |
| 01-23.txt | AC | 166 ms | 10612 KiB |
| 01-24.txt | AC | 180 ms | 10472 KiB |
| 01-25.txt | AC | 183 ms | 10684 KiB |
| 01-26.txt | AC | 149 ms | 10400 KiB |
| 01-27.txt | AC | 123 ms | 8144 KiB |
| 01-28.txt | AC | 133 ms | 8992 KiB |
| 01-29.txt | AC | 123 ms | 8528 KiB |
| 01-30.txt | AC | 159 ms | 9660 KiB |