QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#85208 | #4233. Reset | TheOneYouWant | WA | 2ms | 3560kb | C++20 | 2.0kb | 2023-03-07 10:47:29 | 2023-03-07 10:47:31 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define int long long int
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define ln '\n'
template<typename T1,typename T2>
ostream& operator <<(ostream& c,pair<T1,T2> &v){
c<<"("<<v.fi<<","<<v.se<<")"; return c;
}
template <template <class...> class TT, class ...T>
ostream& operator<<(ostream& out,TT<T...>& c){
out<<"{ ";
for(auto &x : c) out<<x<<" ";
out<<"}"; return out;
}
const int MOD = 1e9+7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll n, c;
vector<pii> tasks;
bool check(int val){
priority_queue<pii> q;
rep(i, 0, tasks.size()){
q.push(tasks[i]);
}
// max d, then t
int consumed = 0;
// consumed should be <= val for each
int final = 0;
while(!q.empty()){
auto t = q.top();
q.pop();
if(t.second > MOD){
if(consumed < c*val) consumed += 1;
else final += 1;
continue;
}
int to_almost_fin = t.second / t.first;
to_almost_fin = min(to_almost_fin, val);
to_almost_fin = min(to_almost_fin, c * val - consumed);
consumed += to_almost_fin;
t.second -= to_almost_fin * t.first;
// t.second is the remaining time
if(to_almost_fin == val){
final += 1;
t.second -= min(t.first, t.second);
final += t.second;
continue;
}
if(t.second>0){
q.push({t.second, MOD+t.second});
}
}
if(final > c) return 0;
return 1;
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
cin >> n >> c;
rep(i, 0, n){
int t, d;
cin >> t >> d;
tasks.push_back({d,t});
}
sort(all(tasks));
int l = 0, r = (3e14+c-1)/c;
while(l<r){
int mid = (l+r)/2;
if(check(mid)){
r = mid;
}
else{
l = mid+1;
}
}
cout << l << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3560kb
input:
3 5 17 5 5 2 15 4
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3520kb
input:
2 1345 1344 1 10 10
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 2ms
memory: 3500kb
input:
1 1000000000 1000000000 1
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 2ms
memory: 3496kb
input:
3 2345 333 1 444 2 555 3
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 2ms
memory: 3464kb
input:
1 500 1000 2
output:
250
result:
ok single line: '250'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3440kb
input:
1 499 1000 2
output:
250
result:
ok single line: '250'
Test #7:
score: 0
Accepted
time: 2ms
memory: 3496kb
input:
3 2345 3333 5 4444 6 5555 6
output:
646
result:
ok single line: '646'
Test #8:
score: -100
Wrong Answer
time: 2ms
memory: 3460kb
input:
8 6 40 10 40 10 40 10 40 10 40 10 20 5 4 3 5 3
output:
5
result:
wrong answer 1st lines differ - expected: '4', found: '5'