-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path484B.cpp
More file actions
43 lines (38 loc) · 724 Bytes
/
Copy path484B.cpp
File metadata and controls
43 lines (38 loc) · 724 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include<bits/stdc++.h>
using namespace std;
bool cmp(const int& a,const int& b){
return a>b;
}
struct Solution{
int n,ans,maxn,q;
vector<int> a;
void Solve(){
scanf("%d",&n);
a.resize(n);
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
maxn=max(maxn,a[i]);
}
sort(a.begin(),a.end());
n=unique(a.begin(),a.end())-a.begin();
a.resize(n);
for(int i=0;i<n;i++){
int k=2*a[i];
while(k<maxn+a[i]){
int x=lower_bound(a.begin(),a.end(),k)-a.begin()-1;
if(x==-1){
k+=a[i];
continue;
}
//printf("k=%d a[%d]=%d a[x] mod a[i]=%d\n",k,x,a[x],a[x]%a[i]);
ans=max(ans,a[x]%a[i]);
k+=a[i];
}
}
printf("%d\n",ans);
}
};
int main(){
Solution().Solve();
return 0;
}