Advertisement
phanindhar1

Untitled

Feb 26th, 2014
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<iostream>
  3. using namespace std;
  4. int main()
  5. {
  6. int n;int max=-1;int count=0;
  7. scanf("%d",&n);
  8. int* a=new int[n+1];
  9. for(int i=0;i<n;i++)
  10. {
  11. scanf("%d",&a[i]);
  12. count+=a[i];
  13. if(max<a[i])max=a[i];
  14. }
  15. int max_count=-1;a[n]=0xFFFF;
  16. for(int j=0;j<n;j++)
  17. {
  18. int temp_count=a[j];int temp_index=1,prev;
  19. prev=a[j];
  20. for(int i=j+1;i<n;i++)
  21. {
  22.  
  23. if(a[i] < prev)
  24. {
  25. prev=a[i];
  26. temp_index++;
  27. temp_count+=a[i];
  28. if(temp_count>max_count)max_count=temp_count;
  29. }
  30. else if(prev!=1)
  31. {
  32. prev=prev-1;
  33. temp_index++;
  34. temp_count+=prev;
  35. if(temp_count>max_count)max_count=temp_count;  
  36. }
  37. else break;
  38. }
  39. //printf("%d -- %d\n",j,max_count);
  40. }
  41. printf("%d\n",count-max_count);
  42. }11:50 PM
  43. Open Hangout
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement