QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#397328#6632. Minimize MedianUSP_USP_USP#WA 1ms3616kbC++142.0kb2024-04-23 22:50:572024-04-23 22:50:58

Judging History

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

  • [2024-04-23 22:50:58]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3616kb
  • [2024-04-23 22:50:57]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define int long long
void dbg_out() { cerr << endl; }
template <typename H, typename... T>
void dbg_out(H h, T... t) { cerr << ' ' << h; dbg_out(t...); }
#define dbg(...) { cerr << #__VA_ARGS__ << ':'; dbg_out(__VA_ARGS__); }
using ll = long long;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MAXN = 2e5 + 5;
const int MOD = 1e9+7; //998244353;
const int INF = 0x3f3f3f3f;
const ll INF64 = ll(4e18) + 5;

void solve(){
	int n,m,k;
	cin >> n >> m >> k;
	vector<int> a(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	sort(a.begin(),a.end());
	vector<int> cost(m+1,INF64);
	for(int i = 1; i <= m; i++){
		cin >> cost[i];
	}
	for(int j = 2; j <= m; j++){
		for(int y = 2*j; y <= m; y += j){
			int com = y/j;
			cost[y] = min(cost[y], cost[j] + cost[com]);
		}
	}
	//preciso do menor custo > M 
	for(int i = m-1; i >= 1; i--){
		cost[i] = min(cost[i], cost[i+1]);
	}
	cost[1] = 0;
	int mnover = INF64;
	for(int i = 2; i <= m; i++){
		//i*x >= m+1
		//i >= (m+1)/x
		int x = (m+1 + i-1)/i;
		assert(x <= m);
		mnover = min(mnover, cost[x] + cost[i]);
	}
	for(int i = m; i >= 1; i--){
		cost[i] = min(cost[i], mnover);
	}
	int l = 0;
	int r = m;
	while(l < r){
		int mid = (l+r)/2;
		int at = 0;
		for(int i = 0; i <= (n/2); i++){
			int v = a[i];
			if(v <= mid) continue;
			// v/x < mid+1
			// v/(mid+1) < x
			//x > v/(mid+1)
			int x = v/(mid+1);
			if(v%(mid+1) == 0) x++;
			if(x <= m){
				at += cost[x];
			}else{
				at += mnover;
			}
		}
		if(at <= k){
			r = mid;
		}else{
			l = mid+1;
		}
	}
	cout << r << '\n';
}

signed main(){

    ios::sync_with_stdio(false); cin.tie(NULL);

    int t = 1;
    cin >> t;
    while(t--){
        solve();
    }

    return 0;
}

/*
Makefile:
CXXFLAGS=-Wall -Wextra -Wshadow -g -pedantic -fsanitize=address,undefined -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUGPEDANTIC -std=gnu++17
*/

詳細信息

Test #1:

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

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
1
1

result:

wrong answer 2nd numbers differ - expected: '2', found: '1'