Advertisement
sidjha57

Apple divison

Mar 11th, 2022
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.99 KB | None | 0 0
  1. //Siddharth Jha
  2.  
  3. #include<bits/stdc++.h>
  4. //#include<ext/pb_ds/assoc_container.hpp>
  5. //#include<ext/pb_ds/tree_policy.hpp>
  6. //#include <ext/pb_ds/trie_policy.hpp>
  7. //using namespace __gnu_pbds;
  8. using namespace std;
  9. //typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
  10. //typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pbtrie;
  11.  
  12. #define ll                       long long int
  13. #define mod                      1000000007
  14. #define inf                      1e18
  15. #define pb                       push_back
  16. #define vi                       vector<ll>
  17. #define vs                       vector<string>
  18. #define pii                      pair<ll,ll>
  19. #define ump                      unordered_map
  20. #define mp                       make_pair
  21. #define pq_max                   priority_queue<ll>
  22. #define pq_min                   priority_queue<ll,vi,greater<ll> >
  23. #define all(n)                   n.begin(),n.end()
  24. #define ff                       first
  25. #define ss                       second
  26. #define mid(l,r)                 (l+(r-l)/2)
  27. #define bitc(n)                  __builtin_popcount(n)
  28. #define SET(a)                   memset( a, -1, sizeof a )
  29. #define CLR(a)                   memset( a,  0, sizeof a )
  30. #define Pi                       3.141592653589793
  31. #define loop(i,a,b)              for(int i=(a);i<=(b);i++)
  32. #define looprev(i,a,b)           for(int i=(a);i>=(b);i--)
  33. #define _fast                    ios_base::sync_with_stdio(0);  cin.tie(0);
  34. #define iter(container,it)       for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
  35. #define log(args...)             {string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
  36. #define logarr(arr,a,b)          for(int z=(a);z<=(b);z++) cout<<(arr[z])<<" ";cout<<endl;
  37. template <typename T> T          gcd(T a, T b){if(a%b) return gcd(b,a%b);return b;}
  38. template <typename T> T          lcm(T a, T b){return (a*(b/gcd(a,b)));}
  39. vs tokenizer(string str,char ch) {std::istringstream var((str)); vs v; string t; while(getline((var), t, (ch))) {v.pb(t);} return v;}
  40.  
  41. void err(istream_iterator<string> it) {}
  42. template<typename T, typename... Args>
  43. void err(istream_iterator<string> it, T a, Args... args) {
  44. cout << *it << " = " << a << endl;
  45. err(++it, args...);
  46. }
  47. ll apple_divide (ll i, ll s1, ll s2, vi& a, ll n) {
  48.     if (i == n)
  49.         return abs(s1-s2);
  50.  
  51.     return min (apple_divide(i+1,s1+a[i],s2,a,n),apple_divide(i+1,s1,s2+a[i],a,n));
  52. }
  53. void solve() {
  54.     ll n,sum=0; cin >> n;
  55.     vi a(n);
  56.     loop (i,0,n-1) {
  57.          cin >> a[i];
  58.          sum += a[i];
  59.     }
  60.    
  61.     cout << apple_divide(0,0,0,a,n);  
  62. }
  63.  
  64. int main(int argc, char const *argv[]){
  65.     _fast
  66.   //#ifndef ONLINE_JUDGE
  67.         //freopen("input.txt", "r", stdin);
  68.         //freopen("output.txt", "w", stdout);
  69.   //#endif
  70.     ll t=1;
  71.     while(t--){
  72.      solve();
  73.     }
  74.   return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement