Submission #71848249
Source Code Expand
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using mint = modint998244353;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vmi = vector<mint>;
using vvmi = vector<vmi>;
using vvvmi = vector<vvmi>;
#define all(a) (a).begin(), (a).end()
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)
void solve(){
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n, m; cin >> n >> m;
vll a(n), b(m);
rep(i, n)cin >> a[i];
rep(i, m)cin >> b[i];
sort(all(b));
vll s(m+1, 0);
rep(i, m)s[i+1] = s[i] + b[i];
mint ans = 0;
rep(i, n){
ll c = lower_bound(all(b), a[i]) - begin(b);
ll t = c*a[i] - s[c] + s[m] - s[c] - a[i]*(m-c);
//cout << t << endl;
ans += mint(t);
}cout << ans.val() << endl;
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Sum of Differences |
| User | applejam |
| Language | C++23 (GCC 15.2.0) |
| Score | 400 |
| Code Size | 1144 Byte |
| Status | AC |
| Exec Time | 78 ms |
| Memory | 10376 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 | 3460 KiB |
| 00-sample-02.txt | AC | 1 ms | 3552 KiB |
| 01-01.txt | AC | 2 ms | 3744 KiB |
| 01-02.txt | AC | 2 ms | 3744 KiB |
| 01-03.txt | AC | 2 ms | 3876 KiB |
| 01-04.txt | AC | 2 ms | 3712 KiB |
| 01-05.txt | AC | 2 ms | 3660 KiB |
| 01-06.txt | AC | 2 ms | 3808 KiB |
| 01-07.txt | AC | 2 ms | 3876 KiB |
| 01-08.txt | AC | 2 ms | 3764 KiB |
| 01-09.txt | AC | 2 ms | 3800 KiB |
| 01-10.txt | AC | 1 ms | 3716 KiB |
| 01-11.txt | AC | 2 ms | 3540 KiB |
| 01-12.txt | AC | 2 ms | 3680 KiB |
| 01-13.txt | AC | 2 ms | 3876 KiB |
| 01-14.txt | AC | 2 ms | 3712 KiB |
| 01-15.txt | AC | 1 ms | 3552 KiB |
| 01-16.txt | AC | 1 ms | 3552 KiB |
| 01-17.txt | AC | 56 ms | 9060 KiB |
| 01-18.txt | AC | 59 ms | 8292 KiB |
| 01-19.txt | AC | 32 ms | 8008 KiB |
| 01-20.txt | AC | 14 ms | 5688 KiB |
| 01-21.txt | AC | 78 ms | 10312 KiB |
| 01-22.txt | AC | 39 ms | 10308 KiB |
| 01-23.txt | AC | 38 ms | 10184 KiB |
| 01-24.txt | AC | 51 ms | 10184 KiB |
| 01-25.txt | AC | 53 ms | 10312 KiB |
| 01-26.txt | AC | 29 ms | 10376 KiB |
| 01-27.txt | AC | 31 ms | 7984 KiB |
| 01-28.txt | AC | 36 ms | 8632 KiB |
| 01-29.txt | AC | 31 ms | 8500 KiB |
| 01-30.txt | AC | 58 ms | 9352 KiB |