Submission #471335

#TimeUsernameProblemLanguageResultExecution timeMemory
471335FgdxxPotatoes and fertilizers (LMIO19_bulves)C++17
0 / 100
1086 ms308 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n; cin>>n; vector<int>odp; vector<pair<int,int>>licz; int con1=0,con2=0; for(int i=0;i<n;i++) { int a,b; cin>>a>>b; licz.push_back({a,b}); con1+=a; con2+=b; } if(con1>=con2) { int p=1; long long w=0; while(licz[0].first<licz[0].second) { if(licz[p].first<=licz[p].second) p++; else { licz[p].first--; licz[0].first++; w+=p; } } p=n-2; /*for(int j=0;j<n;j++) cout<<licz[j].first<<" "<<licz[j].second<<endl; cout<<"xx--xx--xx"<<endl;*/ while(licz[n-1].first<licz[n-1].second) { if(licz[p].first<=licz[p].second) p--; else { licz[p].first--; licz[n-1].first++; w+=n-1-p; } } /*for(int j=0;j<n;j++) cout<<licz[j].first<<" "<<licz[j].second<<endl; cout<<"xx--xx--xx"<<endl;*/ for(int i=1;i<n-1;i++) { int x,z; x=i-1; z=i+1; while(licz[i].first<licz[i].second) { if(x!=0) { int o,u; o=licz[x].first-licz[x].second; u=licz[i].second-licz[i].first; o=min(o,u); w+=o*(i-x); licz[i].first+=o; licz[x].first-=o; x--; } if(licz[i].first>=licz[i].second) break; if(z!=n-1) { int o,u; o=licz[z].first; u=licz[i].second-licz[i].first; o=min(o,u); w+=o*(z-i); licz[i].first+=o; licz[z].first-=o; z++; } } } cout<<w<<endl; } 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...