Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <set>
- #include <tuple>
- #include <vector>
- using namespace std;
- ifstream fin("roata.in");
- ofstream fout("roata.out");
- struct tip1{
- int suma,indice;
- bool operator<(const tip1& term)const {
- return tie(suma,indice)<tie(term.suma,term.indice);
- }
- };
- int v[365];
- vector <int> v1;
- set <tip1> s;
- int n,p,i,a;
- long long tot;
- tip1 x;
- int main()
- {
- fin>>n>>p;
- set<tip1>::iterator it;
- for(i=1;i<=p;i++){
- fin>>a;
- tot+=a;
- if(s.size()!=n){
- x.suma=a;
- x.indice=i;
- v[i]=i;
- s.insert(x);
- }
- else{
- it=s.begin();
- x=*it;
- x.suma+=a;
- s.erase(it);
- s.insert(x);
- v1.push_back(v[x.indice]);
- v[x.indice]=i;
- }
- }
- for(it=s.begin();it!=s.end();++it){
- v1.push_back(v[(*it).indice]);
- }
- fout<<tot<<'\n';
- for(auto it2:v1){
- fout<<it2<<" ";
- }
- fout<<'\n';
- it=s.end();
- --it;
- fout<<(*it).indice<<'\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement