Submission #415369

#TimeUsernameProblemLanguageResultExecution timeMemory
415369HadiHosseiniJob Scheduling (CEOI12_jobs)C++14
40 / 100
357 ms24868 KiB
#include <bits/stdc++.h> using namespace std; void show(long long cur, vector<pair<int, int>> v, int n, int d, int m) { int j = 0; for(int day = 1 ; day <= n ; day++){ long long rev = cur; while(j < m && rev && v[j].first <= day){ if(v[j].first <= day + d){ cout << v[j].second << " "; rev--; j++; } } cout << "0\n"; } } bool f(long long cur, vector<pair<int, int>> v, int n, int d, int m) { int j = 0; for(int day = 1 ; day <= n ; day++){ long long rev = cur; while(j < m && rev && v[j].first <= day){ if(v[j].first <= day + d){ rev--; j++; } else { return false; } } } if(j == m) return true; return false; } long long bs(vector<pair<int, int>> v, int n, int d, int m){ long long lo = -1; long long hig = n; for(long long i = hig - lo; i; i /= 2){ while(lo + i <= hig && !f(lo + i, v, n, d, m)) lo += i; } return lo + 1; } int main(){ ios::sync_with_stdio(0); cin.tie(0); int n, d, m; cin >> n >> d >> m; vector<pair<int, int>> v(m); for(int i = 1 ; i <= m; i++){ cin >> v[i - 1].first; v[i - 1].second = i; } sort(v.begin(), v.end()); long long ans = bs(v, n, d, m); cout << ans << "\n"; show(ans, v, n, d, m); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...