Submission #1094559

#TimeUsernameProblemLanguageResultExecution timeMemory
1094559stefdascaSelf Study (JOI22_ho_t2)C++14
100 / 100
190 ms9576 KiB
// https://stefdasca.ro -> for tutoring #include <iostream> #include <vector> using namespace std; int solve(long long target, int n, int m, vector<int> &classes, vector<int> &study) { vector <long long> required(n); for (int i = 0; i < n; i++) { required[i] = target; } long long hours = 1LL * n * m; // how many hours of study i have left // find out classes for which it's better to go to the courses for (int i = 0; i < n; i++) { if (classes[i] > study[i]) { long long needed = required[i] / classes[i]; if (required[i] % classes[i] > 0) { needed++; } if (needed > m) { needed = m; } required[i] = max(0LL, required[i] - needed * classes[i]); hours -= needed; if (hours < 0) { return 0; } } } // subtract comprehension value based on remaining time for (int i = 0; i < n; i++) { long long needed = required[i] / study[i]; if (required[i] % study[i] > 0) { needed++; } hours -= needed; if (hours < 0) { return 0; } } return 1; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; vector <int> classes(n), study(n); for (int i = 0; i < n; i++) { cin >> classes[i]; } for (int i = 0; i < n; i++) { cin >> study[i]; } long long L = 0; long long R = 1e18; long long ans = 0; while (L <= R) { long long mid = (L + R) / 2; if (solve(mid, n, m, classes, study)) { ans = mid; L = mid + 1; } else { R = mid - 1; } } cout << ans << '\n'; 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...