QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#537607 | #7523. Partially Free Meal | New_Folder# | WA | 221ms | 20164kb | C++14 | 1.8kb | 2024-08-30 16:36:03 | 2024-08-30 16:36:03 |
Judging History
answer
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define int long long
//#define pi 3.1415926
typedef long long ll;
using namespace std;
int mod=998244353;
int fp(int a,int b){
int ans=1;
while(b){
if(b&1) ans*=a,ans%=mod;
a*=a,a%=mod;
b>>=1;
}
return ans;
}
vector<pair<int,int>> vec;
bool ccmp(pair<int,int> p1,pair<int,int> p2){
return p1.second<p2.second;
}
struct cmp{
bool operator()(int p1,int p2){
if(vec[p1].first+vec[p1].second<vec[p2].first+vec[p2].second) return 0;
else if(vec[p1].first+vec[p1].second>vec[p2].first+vec[p2].second) return 1;
else{
if(vec[p1].second<vec[p2].second) return 1;
else return 0;
}
}
};
void solve(){
int n;cin>>n;
int in1,in2;int ptr=0;
vec.resize(n);
set<int> vis;
priority_queue<int,vector<int>,greater<int>> q1;
priority_queue<int,vector<int>,cmp> q2;
for(int i=0;i<=n-1;i++) cin>>in1>>in2,vec[i]=make_pair(in1,in2);
sort(vec.begin(),vec.end(),ccmp);
for(int i=0;i<=n-1;i++) q2.push(i);
vector<int> ans(n+1);int tmp=0;
for(int z=1;z<=n;z++){
bool flag=0;
while(!q2.empty()&&vis.count(q2.top())) q2.pop();
if(q2.empty()) ans[z]=q1.top(),q1.pop();
else if(q1.empty()) ans[z]=vec[q2.top()].first+vec[q2.top()].second-tmp+ans[z-1],flag=1;
else{
if(vec[q2.top()].first+vec[q2.top()].second-tmp<=q1.top()) ans[z]=vec[q2.top()].first+vec[q2.top()].second-tmp+ans[z-1],flag=1;
else ans[z]=ans[z-1]+q1.top(),q1.pop();
}
if(flag){
tmp=vec[q2.top()].second;
vis.insert(q2.top());q2.pop();
while(ptr<=n-1&&vec[ptr].second<=tmp){
if(vis.count(ptr)) ptr++;
else vis.insert(ptr),q1.push(vec[ptr].first),ptr++;
}
}
}
for(int i=1;i<=n;i++) cout<<ans[i]<<"\n";
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
//int t;cin>>t;while(t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3564kb
input:
3 2 5 4 3 3 7
output:
7 11 16
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 221ms
memory: 20164kb
input:
200000 466436993 804989151 660995237 756645598 432103296 703610564 6889895 53276988 873617076 822481192 532911431 126844295 623111499 456772252 937464699 762157133 708503076 786039753 78556972 5436013 582960979 398984169 786333369 325119902 930705057 615928139 924915828 506145001 164984329 208212435...
output:
1318594 3208018 5570526 7340845 9223347 11487338 13751811 16532451 17560831 19309829 21108821 22990148 24475695 25467968 26430542 27815157 29410889 30978895 32666076 34583473 36594398 37596721 38636691 40422322 42408932 44248691 46082393 47916747 49838235 52476909 55158583 58072674 61026526 64003437...
result:
wrong answer 6th lines differ - expected: '11149865', found: '11487338'