Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

No_stop

Posted by 070101070260 at 2013-10-15 19:11:25
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <vector>
#include <utility>
#include <set>
#include <cstdlib>
using namespace std;
typedef pair<int, int> PII;
typedef long long LL;
const int maxn = 1000005;
const int mask = (1 << 17) - 1;
int a[maxn];
int main() {
    ios::sync_with_stdio(false);
    int n, i, j, k, t;
    cin >> n >> k;
    int low = maxn;
    for (i = 1; i <= n; ++i) {
        cin >> t;
        int l = max(0, t - k);
        int r = t;
        low = min(low, t);
        a[l]++, a[r + 1]--;
    }
    for (i = 1; i < maxn; ++i) {
        a[i] += a[i - 1];
    }
    for (i = low; i >= 1; --i) {
        int cnt = 0;
        for (j = i; j < maxn; j += i) {
            cnt += a[j];
        }
        if (cnt >= n) {
            cout << i << endl;
            break;
        }
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator