Submission #81709

#TimeUsernameProblemLanguageResultExecution timeMemory
81709luckyboyKarte (COCI18_karte)C++14
72 / 120
126 ms8032 KiB
/**Lucky Boy**/ #include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i <= (b); ++i) #define FORD(i, a, b) for (int i = (a); i >= (b); --i) #define pb push_back #define mp make_pair #define F first #define S second #define maxc 1000000007 #define maxn 500005 #define maxm 500005 #define pii pair <int,int> #define Task "Karte" template <typename T> inline void read(T &x){char c;bool nega=0;while((!isdigit(c=getchar()))&&(c!='-'));if(c=='-'){nega=1;c=getchar();}x=c-48;while(isdigit(c=getchar())) x=x*10+c-48;if(nega) x=-x;} template <typename T> inline void writep(T x){if(x>9) writep(x/10);putchar(x%10+48);} template <typename T> inline void write(T x){if(x<0){putchar('-');x=-x;}writep(x);putchar(' ');} template <typename T> inline void writeln(T x){write(x);putchar('\n');} using namespace std; int n,k,a[maxn << 1],cnt; int Calc(int x) { int cnt = 0; FOR(i,0,n-1) if (cnt < a[i+x]) ++cnt; return cnt; } int main() { //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); //freopen(Task".inp", "r",stdin); //freopen(Task".out", "w",stdout); read(n),read(k); FOR(i,1,n) read(a[i]); sort(a+1,a+n+1); FOR(i,1,n) a[i+n] = a[i]; int l = 1,r = n + 1; while (r - l > 1) { int mid = (l+r) >> 1;; if (Calc(mid) >= k) l = mid; else r = mid; } if (Calc(l) == k) FORD(i,n-1,0) write(a[i+l]); else write(-1); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...