Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//
// main.m
// Sherlock and Array
//
// Created by Nathan Arnold on 11/9/15.
// Copyright © 2015 Nathan Arnold. All rights reserved.
//
#import <Foundation/Foundation.h>
void processTestCase() {
int numberOfElements = 0;
scanf("%d", &numberOfElements);
int elementArray[numberOfElements];
long total = 0;
int subTotal = 0;
for (int i = 0; i<numberOfElements; i++) {
int item = 0;
scanf("%d", &item);
total += item;
elementArray[i] = item;
}
if (numberOfElements == 1) {
printf("YES\n");
return;
}
for (int i = 1; i<numberOfElements; i++) {
subTotal += elementArray[i-1];
if ((subTotal * 2) == total-elementArray[i]) {
printf("YES\n");
return;
}
}
printf("NO\n");
}
int main(int argc, const char * argv[]) {
// @autoreleasepool {
// insert code here...
// NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
int numberOfTestCases = 0;
scanf("%d", &numberOfTestCases);
for (int i = 0; i < numberOfTestCases; i++){
processTestCase();
}
// }
// [pool drain];
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.