QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#127922#6632. Minimize MedianshielderWA 1ms5544kbC++201.9kb2023-07-20 11:42:012023-07-20 11:42:04

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-20 11:42:04]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5544kb
  • [2023-07-20 11:42:01]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+10;
int tt, n, m, k, p;
int a[N], cost[N];
bool check(int x){
      vector<int> pre;
      long long tmp = 0;
      for(int i = 1;i <= p;i++){
        if(a[i] > x) pre.push_back(a[i]);
      }
      for(auto y : pre){
        int z = (y +x)/ (x+1);
        assert(z <= m+1);
        tmp += cost[z];
      }
      return tmp <= k;
}
int main(){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    cin >> tt;
    while(tt--){
         cin >> n >> m >> k;
         for(int i = 1;i <= n;i++){
            cin >> a[i];
         }
         for(int i = 1;i <= m;i++){
            cin >>cost[i];
         }
         sort(a+1, a+n+1);
         p = n/2+1;
         cost[m+1] = k+1;
         for(int i = m-1;i;--i){
            cost[i] = min(cost[i+1], cost[i]);
         }
         for(int i = 2;i <= m;i++){
                int len = min( (int)(sqrt(i) +2), i-1);
                for(int j = 2;j <= len;j++){
                    cost[i] = min(cost[i], cost[j] + cost[(i + j - 1)/j]);
                }
         }
         for(int i = m-1;i;i--){
            cost[i] = min(cost[i], cost[i+1]);
         }
         int p1 = k+1;
         for(int i = 2;i <m;i++){
            p1 = min(p1, cost[i] + cost[(m + i - 1)/ i]);
         }
         cost[m] = min(p1, cost[m]);
        int  p2 = k+1;
         for(int i = 2;i <= m;i++){
            p2 = min(p2, cost[i] + cost[(m+i)/i]);
         }
         cost[m +1] = min(cost[m+1], p2);
         for(int i = m;i;i--){
            cost[i] = min(cost[i], cost[i+1]);
         }
         int l = 0, r = a[p];
         int res;
         while(l<=r){
            int mid = l +r>>1;
            if(check(mid)){
                    res = mid;
                r = mid-1;
            }
            else l = mid+1;
         }
         cout << l << "\n";
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5544kb

input:

3
3 5 0
2 5 2
3 2 4 6 13
3 5 3
2 5 3
3 2 4 6 13
3 5 6
2 5 2
3 2 4 6 13

output:

2
2
0

result:

wrong answer 3rd numbers differ - expected: '1', found: '0'