Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Source #643521:
- #include<stdio.h>
- #define IM -1e9
- int main()
- {
- int n;
- scanf("%d",&n);
- int arr[n];
- int temparr[n];
- int cot = 0;
- int temp = IM;
- int ans = IM;
- int ansarr[n];
- int coa = 0;
- for(int i=0;i<n;i++){
- scanf("%d",&arr[i]);
- if(temp+i >= i){ //continue
- temp = temp+arr[i];
- temparr[cot] = arr[i];
- cot++;
- }else{ //new
- temp = arr[i];
- cot = 0;
- temparr[cot] = arr[i];
- cot++;
- }
- if(temp>ans){
- ans = temp;
- coa = cot;
- for(int i=0;i<cot;i++){
- ansarr[i] = temparr[i];
- }
- }
- }
- if(coa == 0 || ans <= 0){
- printf("Empty sequence");
- }
- else{
- for(int i=0;i<coa;i++){
- printf("%d ",ansarr[i]);
- }
- printf("\n%d",ans);
- }
- }
- /*
- 12
- 4 -6 3 -2 6 -4 -6 6 -6 4 -2 5
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement