Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- main()
- {
- int t, n, i, j, poz, min, max, zisk;
- scanf("%d\n", &t);
- while (t > 0)
- {
- scanf("%d ", &n);
- if (n > 0)
- {
- int *ceny = (int *) calloc(n, sizeof(int));
- max = -1; zisk = 0;
- for (i = 0; i < n; i++)
- {
- scanf("%d", &ceny[i]);
- }
- for(i = 0; i < n; i++)
- {
- for(j = i+1; j < n; j++)
- {
- if(ceny[i] < ceny[i+j] && ceny[i+1]-ceny[i] > max)
- {
- max = ceny[i+1]-ceny[i];
- poz = j;
- }
- }
- i = poz;
- zisk += max;
- }
- printf("Zisk: %d", zisk);
- free(ceny);
- }
- if(n <= 0)
- printf("n musi byt vacsie ako 0!");
- n = -1; zisk = -1; t -= 1;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement