Permalink
Browse files

Solve 6C - Alice, Bob and Chocolate

  • Loading branch information...
1 parent 97907d5 commit aaf5c4b12964920e0a49be0501f8821f9c58ae42 @aeurielesn committed Feb 13, 2011
Showing with 57 additions and 0 deletions.
  1. +57 −0 6/C/alice-bob-and-chocolate.cc
@@ -0,0 +1,57 @@
+/*
+* STATUS = ACCEPTED
+*/
+
+#include <cstdio>
+#include <vector>
+#include <algorithm>
+#include <stack>
+#include <cstring>
+#include <set>
+#include <iostream>
+
+using namespace std;
+
+#define FOR(i,n) for(int i=0; i<n; ++i)
+#define FORI(i,a,n) for(int i=a; i<n; ++i)
+#define SZ(c) ((int)c.size())
+
+int main()
+{
+ #ifndef ONLINE_JUDGE
+ freopen("alice-bob-and-chocolate.in","r",stdin);
+ #endif
+
+ int n, time;
+
+ scanf("%d", &n);
+
+ vector<int> chocolates(n + 2, 0);
+
+ FORI(i, 1, n+1)
+ {
+ scanf("%d", &time);
+ chocolates[i] = chocolates[i-1] + time;
+ }
+ chocolates[n+1] = chocolates[n];
+
+
+ int left = 0, right = n + 1;
+
+ while(right > left)
+ {
+ int alice = chocolates[left], bob = chocolates[n+1] - chocolates[right];
+ if((alice < bob) || (alice == bob))
+ {
+ left++;
+ }
+ else if(bob < alice)
+ {
+ right--;
+ }
+ }
+
+ printf("%d %d\n", left, n - left);
+
+ return 0;
+}

0 comments on commit aaf5c4b

Please sign in to comment.