Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define MAXSTONES 20
- int main(void) {
- unsigned int stones[MAXSTONES] = {0};
- unsigned int pile1 = 0, pile2 = 0;
- int stoneCount = 0;
- int weightDifference = 0;
- int i;
- char contMoving = 1;
- unsigned int biggestStone;
- fscanf(stdin, "%d", &stoneCount);
- for(i = 0; i < stoneCount; i++) {
- fscanf(stdin, "%u", &stones[i]);
- pile1 += stones[i];
- }
- while(contMoving) {
- weightDifference = pile1 - pile2;
- if(weightDifference != 0) {
- biggestStone = 0;
- for(i = 0; i < stoneCount; i++) {
- if(stones[i] < weightDifference && stones[i] > biggestStone) {
- if((pile1 - stones[i]) >= (pile2 + stones[i])) {
- biggestStone = stones[i];
- }
- }
- }
- if(biggestStone != 0) {
- pile1 -= biggestStone;
- pile2 += biggestStone;
- } else {
- contMoving = 0;
- break;
- }
- } else {
- contMoving = 0;
- break;
- }
- }
- fprintf(stdout, "%u\n", weightDifference);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement