Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <algorithm>
- #include <vector>
- using namespace std;
- ifstream cin("numere2.in");
- ofstream cout("numere2.out");
- const int nmax = 3e2;
- const int amax = 1e3;
- int n;
- int a[nmax + 1];
- bool fq[nmax * amax + 1];
- void read(){
- cin >> n;
- for(int i = 1; i <= n; i++)
- cin >> a[i];
- }
- void solve(){
- sort(a + 1, a + n + 1);
- int mx = 0;
- for(int i = 1; i <= n; i++){
- vector <int> nr;
- for(int j = 1; j <= mx; j++)
- if(fq[j])
- nr.push_back(j + a[i]);
- fq[a[i]] = 1;
- mx = max(a[i], mx);
- while(!nr.empty()){
- fq[nr.back()] = 1;
- mx = max(mx, nr.back());
- nr.pop_back();
- }
- }
- int lg = 0, bst = 0;
- for(int i = 1; i <= mx; i++)
- if(fq[i])
- lg++;
- else {
- bst = max(bst, lg);
- lg = 0;
- }
- bst = max(bst, lg);
- cout <<bst;
- }
- int main()
- {
- read();
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement