1 solutions
-
0
C++ :
#include<iostream> #include<algorithm> #include<cstdio> #include<cmath> #include<cstring> #include<vector> #include<queue> #include<map> using namespace std; const long long N=100+5; long long a,n,p[N],gs,v[N],tmp[N],t; int main() { cin>>a>>n; for (int i=1;i<=n;i++) cin>>p[i]; gs=n; while (1) { sort(p+1,p+gs+1); t=0; for (int i=1;i<=n;i++) v[i]=0,tmp[i]=0; for (long long i=1;i<=gs;i++) { if (v[i]) continue; if (i+a-1>gs) { tmp[++t]=p[i]; continue; } if (p[i]!=p[i+a-1]) { tmp[++t]=p[i]; continue; } tmp[++t]=p[i]+1; for (int j=i;j<=i+a-1;j++) v[j]=1; } if (gs==t) break; gs=t; for (int i=1;i<=gs;i++) p[i]=tmp[i]; } if (gs==1) cout<<p[gs]<<endl; else cout<<p[gs]+1<<endl; return 0; }
- 1
Information
- ID
- 885
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- 10
- Tags
- (None)
- # Submissions
- 2
- Accepted
- 1
- Uploaded By