Minimum sum of numbers
You definitely can make your code cleaner :


Your function main does all the job, that's usually quite bad. You can, at least, separate two aspects : reading the input (and store it in an array) and processing the input. That would be a little bit easier to read
Use comments ! Not even one here, that's pretty bad.
Better use of new lines : you really tend to use way too much of them. Multiple new lines should be used to separate parts of code that do quite different things, but in no case you should use two just after an if
Better variable naming : just one example, but it's because it's very common : i . I really don't like it, because by reading the index, you don't know through what you iterate. The best example for that are matrices, i and j are far less understandable than iRow and iCol
The indentation is also quite bad, especially at the end
You don't free the memory you have allocated.
Have you tried removing your condition on flag in your while ? You set it to false, then there's an if/else, and in both cases, it's set to true again.