Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <set>
  4. #include <tuple>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. ifstream fin("roata.in");
  10. ofstream fout("roata.out");
  11.  
  12. struct tip1{
  13.     int suma,indice;
  14.     bool operator<(const tip1& term)const {
  15.         return tie(suma,indice)<tie(term.suma,term.indice);
  16.     }
  17. };
  18.  
  19. int v[365];
  20. vector <int> v1;
  21. set <tip1> s;
  22.  
  23. int n,p,i,a;
  24. long long tot;
  25. tip1 x;
  26.  
  27. int main()
  28. {
  29.     fin>>n>>p;
  30.     set<tip1>::iterator it;
  31.     for(i=1;i<=p;i++){
  32.         fin>>a;
  33.         tot+=a;
  34.         if(s.size()!=n){
  35.             x.suma=a;
  36.             x.indice=i;
  37.             v[i]=i;
  38.             s.insert(x);
  39.         }
  40.         else{
  41.             it=s.begin();
  42.             x=*it;
  43.             x.suma+=a;
  44.             s.erase(it);
  45.             s.insert(x);
  46.             v1.push_back(v[x.indice]);
  47.             v[x.indice]=i;
  48.         }
  49.     }
  50.     for(it=s.begin();it!=s.end();++it){
  51.         v1.push_back(v[(*it).indice]);
  52.     }
  53.     fout<<tot<<'\n';
  54.     for(auto it2:v1){
  55.         fout<<it2<<" ";
  56.     }
  57.     fout<<'\n';
  58.     it=s.end();
  59.     --it;
  60.     fout<<(*it).indice<<'\n';
  61.     return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement