1 条题解

  • 0
    @ 2023-6-21 20:08:53

    C++ :

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    
    #define DEBUG(args...) fprintf(stderr, args)
    
    #define FOR(i, l, r) for(int i=(l); i<=(r); ++i)
    #define REP(i, l, r) for(int i=(l); i< (r); ++i)
    #define DFR(i, l, r) for(int i=(l); i>=(r); --i)
    #define DRP(i, l, r) for(int i=(l); i> (r); --i)
    
    typedef long long LL;
    
    template<class T>T Min(const T &a, const T &b) {return a < b ? a : b;}
    template<class T>T Max(const T &a, const T &b) {return a > b ? a : b;}
    template<class T>bool Chkmin(T &a, const T &b) {return a > b ? a=b, 1 : 0;}
    template<class T>bool Chkmax(T &a, const T &b) {return a < b ? a=b, 1 : 0;}
    
    namespace FI {
    	const int SIZE = 1 << 15 | 1;
    	char buf[SIZE], *front, *back;
    	void NextChar(char &c) {
    		if(front == back) back = (front=buf) + fread(buf, 1, SIZE, stdin);
    		c = front==back ? (char)EOF : *front++;
    	}
    	void NextInt(int &x) {
    		char c;
    		for(NextChar(c); c>'9'||c<'0'; NextChar(c)) ;
    		for(x=0; c>='0'&&c<='9'; NextChar(c)) x = x*10+c-'0';
    	}
    }
    
    const int SN = 100000 + 47;
    const int SK = 1000000 + 47;
    const LL INF = 1000000000000LL;
    
    LL a[SK], b[SK], ans;
    int w[SN], d[SN], n, m, k;
    
    void Get(int, int *, LL *);
    bool Check(LL, int, int *);
    
    int main() {
    
    	int x, y, z;
    
    	FI::NextInt(k), FI::NextInt(n), FI::NextInt(m);
    	FOR(i, 1, n) FI::NextInt(w[i]);
    	FOR(i, 1, m) FI::NextInt(d[i]);
    
    	Get(n, w, a), Get(m, d, b);
    
    	FOR(i, 1, k) Chkmax(ans, a[i]+b[k-i+1]);
    
    	printf("%lld\n", ans);
    
    	return 0;
    
    }
    
    void Get(int x, int *a, LL *p) {
    	LL l = 1, r = INF, mid;
    	while(l+1 < r)
    		if(Check(mid=l+r>>1, x, a)) r = mid;
    		else l = mid;
    	l = Check(l, x, a) ? l : l+1;
    	int t = 0;
    	FOR(i, 1, x) for(LL j=a[i]; j<=l; j+=a[i]) p[++t] = j;
    	std::sort(p+1, p+t+1);
    }
    
    bool Check(LL x, int y, int *a) {
    	LL t = 0;
    	FOR(i, 1, y) t += x/a[i];
    	return t >= k;
    }
    
    • 1

    信息

    ID
    1039
    时间
    3000ms
    内存
    512MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者