Submission #1124813

#TimeUsernameProblemLanguageResultExecution timeMemory
1124813vs358Stove (JOI18_stove)C++20
0 / 100
0 ms320 KiB
#include <bits/stdc++.h> #include <queue> #include <iostream> using namespace std; #define int long long typedef pair<int, int> pi; signed main(){ int n, s; cin >> n >> s; vector<int> sch[1005]; int counter[1005]; memset(counter, 0, sizeof(counter)); pi bottom = make_pair(-1, -1); priority_queue<pi> pq; for(int i = 0; i < n; i++){ cout << i << endl; vector<int> temp; for(int j = 0; j < s; j++){ int x; cin >> x; temp.push_back(x); } sort(temp.begin(), temp.end(), greater<int>()); sch[i] = temp; if(bottom.first == -1 or temp[0] < bottom.first){ bottom = make_pair(temp[0], i); } pq.push(make_pair(temp[s-1], i)); } int ans = pq.top().first - bottom.first; while(!pq.empty()){ pi curr = pq.top(); pq.pop(); ans = min(curr.first - bottom.first, ans); //max - min if(counter[curr.second] == s-1) break; else { counter[curr.second]++; pq.push(make_pair(counter[curr.second], curr.second)); if(sch[curr.second][counter[curr.second]] < bottom.first){ bottom = make_pair(sch[curr.second][counter[curr.second]], curr.second); } } } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...