QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#642074 | #8548. China Convex Polygon Contest | youthpaul | WA | 14ms | 3844kb | C++20 | 1.7kb | 2024-10-15 09:42:46 | 2024-10-15 09:42:46 |
Judging History
answer
#include<bits/stdc++.h>
#define fore(i,l,r) for(int i=(int)(l);i<(int)(r);++i)
#define fi first
#define se second
#define endl '\n'
#define ull unsigned long long
#define ALL(v) v.begin(), v.end()
#define Debug(x, ed) std::cerr << #x << " = " << x << ed;
const int INF=0x3f3f3f3f;
const long long INFLL=1e18;
typedef long long ll;
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
int t;
std::cin >> t;
while(t--){
int n, m;
std::cin >> n >> m;
std::vector<int> a(n + 2);
fore(i, 1, n + 1) std::cin >> a[i];
a[n + 1] = m;
std::vector<int> b(n);
fore(i, 0, n) std::cin >> b[i];
std::sort(ALL(b));
std::vector<int> t;
int lst = 0;
for(auto x : b){
if(lst + x >= m) break;
lst += x;
t.push_back(lst);
}
int idx = t.size() - 1;
int ans = 0;
std::priority_queue<int> q;
for(int i = n + 1; i > 0; --i){
int l = a[i - 1], r = a[i];
int cnt = 0, t1 = 0;
while(idx >= 0 && t[idx] >= r) --idx;
while(idx >= 0 && t[idx] >= l){
++cnt;
t1 = t[idx];
--idx;
}
if(!cnt) q.push(r - l);
else{
fore(k, 0, cnt - 1){
if(q.empty()) break;
ans += q.top();
q.pop();
}
ans += r - t1;
if(q.empty() || q.top() < r - t1){
int x = (q.empty() ? 0 : q.top());
q.push(t1 - l + x);
}
else{
ans += q.top() - r + t1;
q.pop();
q.push(r - l);
}
}
}
std::cout << ans << endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
input:
3 3 10 1 5 9 1 2 3 3 10 1 5 9 1 1 4 3 10 1 5 9 1 5 10
output:
9 9 7
result:
ok 3 number(s): "9 9 7"
Test #2:
score: -100
Wrong Answer
time: 14ms
memory: 3844kb
input:
10000 9 879847766 125098132 150509852 181700303 196375322 519766842 560891576 609151480 721527163 805167083 99031467 66330518 6283986 21388462 41109537 83628243 116141243 144052767 192448599 8 30 5 12 16 19 20 23 25 27 3 1 1 4 2 8 2 3 8 30 4 10 13 16 17 20 23 27 6 3 1 2 3 4 7 2 7 586479012 37693706 ...
output:
874601775 30 27 548785306 29 880398075 28 861438927 981325807 748003628 551716288 759475944 30 27 32 940852557 28 32 29 789162471 30 28 31 28 29 30 29 27 31 890986598 828605804 28 26 31 819236826 956911422 583799124 884156431 934413263 30 29 877443566 28 27 29 519965664 27 27 618111955 28 27 9121530...
result:
wrong answer 1st numbers differ - expected: '858888761', found: '874601775'