dikki99's blog

By dikki99, history, 17 months ago, In English

include

include<math.h>

include

using namespace std;

bool check(int* arr,int n,int k){ int sum=0; int curr=0; for(int i=0;i<k;i++) sum+=arr[i]; curr=sum; for(int i=k;i<n;i++){ curr+=arr[i]-arr[i-k]; if(curr!=sum) return false; } return true; }

int main(){ int t; cin>>t; while(t--){ int n,k; cin>>n>>k; int arr[n]; map<int,int> m; for(int i=0;i<n;i++){ cin>>arr[i]; m[arr[i]]++; } if(n==k){ cout<<k<<endl; for(int i=0;i<n;i++) cout<<arr[i]<<" "; cout<<endl; } else if(m.size()>k||m.size()==n){ cout<<-1<<endl; } else if(check(arr, n, k)){ cout<<n<<endl; for(int i=0;i<n;i++){ cout<<arr[i]<<" "; } cout<<endl; } else{ cout<<n*m.size()<<endl; for(int i=0;i<n;i++){ for(map<int, int>::iterator itr=m.begin();itr!=m.end();itr++){ cout<first<<" "; } }

cout<<endl;
}

}// t; return 0; }

This is my code for DIV.2 b question and this giving wrong answer on 4th pretest but it is giving correct output on my local ide.

Read more »

 
 
 
 
  • Vote: I like it
  • -40
  • Vote: I do not like it

By dikki99, history, 17 months ago, In English

link to the problem:-https://codeforces.com/contest/508/problem/C

please explain the logic behind this problem. I have looked into the editorial but it's not clear.

Read more »

 
 
 
 
  • Vote: I like it
  • 0
  • Vote: I do not like it