CSES - Datatähti 2017 alku - Results
Submission details
Task:Kolikot
Sender:Alex
Submission time:2016-10-13 21:58:47 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int etsi(long int, std::vector<std::pair<long int, long int> >, long int, long int)':
input/code.cpp:34:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(k<v.size()-1&&v.at(k+1).first==x){
                  ^
input/code.cpp: In function 'int main(int, char**)':
input/code.cpp:142:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                     if(k<v.size()-1&&v.at(k+1).first==i){
                                   ^
input/code.cpp:146:26: error: no match for 'operator==' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long int, long int> > >::value_type {aka std::pair<long int, long int>}' and 'long int')
                if(v.at(k)==i){
                          ^
input/code.cpp:146:26: note: candidates are:
In file included from /usr/include/c++/4.8/bits/stl_algo.h:66:0,
                 from /usr/include/c++/4.8/algorithm:62,...

Code

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/* 
 * File:   main.cpp
 * Author: alex
 *
 * Created on October 6, 2016, 9:19 PM
 */
#include <cstdlib>

using namespace std;

#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
/*
 * 
 */

int etsi (long x,vector< pair<long,long> > v, long o , long d){ 
long n=v.size();
    long k=0; 
 if(d==0){ 
    for (long b = n/2; b >= 1; b /= 2) {
        while(k+b<n&&v.at(k+b).first<x){
            k+=b;
        }
    }    
   if(k<v.size()-1&&v.at(k+1).first==x){
       k++;
   }
 }else{
     k=d;
 }
   
   
   
   
   while(o!=-1&&v.at(k)>=v.at(o)){
       k--;
       if(k<0){
       return 0;
        }
   }
   if(k<0){
       return 0;
   }
   
   if(v.at(k).first>x){
       return 0;
   }
   
      if(x-v.at(k).first*v.at(k).second<v.at(k).first) {
          return 1; 
      } 
   
   for (int i = v.at(k).second; i > 0; i--) {   
           int pa= etsi(x-v.at(k).first*i,v,k,0);
         
           if(pa==1){
               return 1;
               
           }
    }

   
   return 0;
}














int main(int argc, char** argv) {
    
    long n;
    cin >> n;
    long l[n];
  
    long a;
    long j=0;
    vector< pair<long,long> > v;
    
    for (int i = 0; i < n; i++) {
        
        cin >> a;
        l[i]=a;

    }
    
    sort(l, l+n);
    a=l[0];
    long r=1;
    long f;
for (int i = 1; i < n; i++) {        
        f=l[i];
        if(f==a){
            r++;
            a=f;
        }else{
            pair <int,int> p=make_pair(a,r);
            v.push_back(p);
            j++;
            a=f;
            r=1;
        }

    }
    pair <int,int> p=make_pair(a,r);
            v.push_back(p);
            
        
            

   
            
      long i=1;
      long q =0;
      while(etsi(i,v,-1,q)){
          i++;
                long n=v.size();
               long k=0;
                    for (long b = n/2; b >= 1; b /= 2) {
                        while(k+b<n&&v.at(k+b).first<i){
                          k+=b;
                            }
                     }    
                    if(k<v.size()-1&&v.at(k+1).first==i){
                        k++;
                        }
               
               if(v.at(k)==i){
                   i=i*2-1;
               }else{
               q=k;
               }
                        }
            
      cout << i;

    
    return 0;
}