| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1327608 | candi_ositos | Feast (NOI19_feast) | C++20 | 203 ms | 16580 KiB |
#include <bits/stdc++.h>
using namespace std;
void solve(){
int n, k, tp=0;
long long ts=0;
cin>>n>>k;
vector <pair <long long, pair <int, int> > > a(n), s;
for(int i=0; i<n; ++i){
cin>>a[i].first;
a[i].second={i-1, i+1};
}
set <pair <long long, int> > nl, pl;
s.push_back(a[0]);
for(int i=1; i<n; ++i){
if(a[i].first==0){
continue;
}
if(a[i].first*a[i-1].first>0){
s[s.size()-1].first+=a[i].first;
}
else{
s.push_back(a[i]);
s[s.size()-1].second={s.size()-2, s.size()};
}
}
n=s.size();
for(int i=0; i<n; ++i){
if(s[i].first>0){
pl.insert({s[i].first, i});
}
else{
nl.insert({-s[i].first, i});
}
}
while(k<pl.size()){
pair <long long, int> d, e;
for(auto i:pl){
d=i;
break;
}
for(auto i:nl){
e=i;
break;
}
int i;
if(d.first<e.first){
pl.erase(d);
i=d.second;
}
else{
nl.erase(e);
i=e.second;
}
int l=s[i].second.first, r=s[i].second.second;
if(l<0){
s[r].second.first=l;
}
else if(r>=n){
s[l].second.second=r;
}
else{
s[i].first+=s[l].first+s[r].first;
if(s[i].first>0){
pl.erase({s[l].first, l});
pl.erase({s[r].first, r});
pl.insert({s[i].first, i});
}
else{
nl.erase({-s[l].first, l});
nl.erase({-s[r].first, r});
nl.insert({-s[i].first, i});
}
s[i].second.second=s[r].second.second;
s[i].second.first=s[l].second.first;
l=s[i].second.first;
r=s[i].second.second;
if(l>=0){
s[l].second.second=i;
}
if(r<n){
s[r].second.first=i;
}
}
}
for(auto i:pl){
ts+=i.first;
}
cout<<ts<<"\n";
return;
}
int main(){
int T=1;
//cin>>T;
while(T--){
solve();
}
return 0;
}| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
