fork download
  1. // Source: Yassinezeort
  2.  
  3. #include <bits/stdc++.h>
  4.  
  5. using namespace std;
  6.  
  7. #define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
  8.  
  9.  
  10. void insert(vector<int> &v , int a){
  11. v.push_back(a);
  12. v[0]++;
  13. int i = v[0] ;
  14. while(i > 1 && v[i/2] > v[i]){
  15. swap(v[i] , v[i/2]);
  16. i/=2 ;
  17. }
  18. }
  19.  
  20. void del(vector<int> &v){
  21. int sm = v[1] ;
  22. v[1] = v[v[0]] ;
  23. v[0]--;
  24. v.pop_back();
  25. int i = 1 ;
  26. while (true){
  27. int l = 2*i , r = 2*i+1 , smallest = i ;
  28. if (l <= v[0] && v[l] < v[smallest] )
  29. smallest = l ;
  30. if (r <= v[0] && v[r] < v[smallest] )
  31. smallest = r ;
  32. if (smallest != i){
  33. swap(v[i] , v[smallest]) ;
  34. i = smallest ;
  35. }
  36. else
  37. break ;
  38. }
  39. }
  40.  
  41.  
  42. int main() {
  43. io;
  44. int n , k ; cin >> n >> k ;
  45. vector<int> heap(1 ,0);
  46. for (int i = 0; i < n; ++i) {
  47. int a ; cin >> a ;
  48. insert(heap , a) ;
  49. if (heap[0] > k){
  50. del(heap);
  51. }
  52. }
  53. long long res = 0 ;
  54. for (int i = 1 ; i <= heap[0] ; ++i) {
  55. res += heap[i];
  56. }
  57. cout << res ;
  58.  
  59. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:3: error: illegal character: '#'
#include <bits/stdc++.h>
^
Main.java:3: error: class, interface, or enum expected
#include <bits/stdc++.h>
         ^
Main.java:7: error: illegal character: '#'
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
^
Main.java:7: error: class, interface, or enum expected
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
        ^
Main.java:7: error: class, interface, or enum expected
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
                                             ^
Main.java:7: error: class, interface, or enum expected
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
                                                            ^
Main.java:12: error: class, interface, or enum expected
    v[0]++;
    ^
Main.java:13: error: class, interface, or enum expected
    int i = v[0] ;
    ^
Main.java:14: error: class, interface, or enum expected
    while(i > 1 && v[i/2] > v[i]){
    ^
Main.java:16: error: class, interface, or enum expected
        i/=2 ;
        ^
Main.java:17: error: class, interface, or enum expected
    }
    ^
Main.java:22: error: class, interface, or enum expected
    v[1] = v[v[0]] ;
    ^
Main.java:23: error: class, interface, or enum expected
    v[0]--;
    ^
Main.java:24: error: class, interface, or enum expected
    v.pop_back();
    ^
Main.java:25: error: class, interface, or enum expected
    int i = 1 ;
    ^
Main.java:26: error: class, interface, or enum expected
    while (true){
    ^
Main.java:28: error: class, interface, or enum expected
        if (l <= v[0] && v[l] < v[smallest] )
        ^
Main.java:30: error: class, interface, or enum expected
        if (r <= v[0] && v[r] < v[smallest] )
        ^
Main.java:32: error: class, interface, or enum expected
        if (smallest != i){
        ^
Main.java:34: error: class, interface, or enum expected
            i = smallest ;
            ^
Main.java:35: error: class, interface, or enum expected
        }
        ^
Main.java:38: error: class, interface, or enum expected
    }
    ^
Main.java:44: error: class, interface, or enum expected
    int n , k ; cin >> n >> k ;
    ^
Main.java:44: error: class, interface, or enum expected
    int n , k ; cin >> n >> k ;
                ^
Main.java:45: error: class, interface, or enum expected
    vector<int> heap(1 ,0);
    ^
Main.java:46: error: class, interface, or enum expected
    for (int i = 0; i < n; ++i) {
    ^
Main.java:46: error: class, interface, or enum expected
    for (int i = 0; i < n; ++i) {
                    ^
Main.java:46: error: class, interface, or enum expected
    for (int i = 0; i < n; ++i) {
                           ^
Main.java:47: error: class, interface, or enum expected
        int a ; cin >> a ;
                ^
Main.java:48: error: class, interface, or enum expected
        insert(heap , a) ;
        ^
Main.java:49: error: class, interface, or enum expected
        if (heap[0] > k){
        ^
Main.java:51: error: class, interface, or enum expected
        }
        ^
Main.java:54: error: class, interface, or enum expected
    for (int i = 1 ; i <= heap[0] ; ++i) {
    ^
Main.java:54: error: class, interface, or enum expected
    for (int i = 1 ; i <= heap[0] ; ++i) {
                     ^
Main.java:54: error: class, interface, or enum expected
    for (int i = 1 ; i <= heap[0] ; ++i) {
                                    ^
Main.java:56: error: class, interface, or enum expected
    }
    ^
Main.java:59: error: class, interface, or enum expected
}
^
37 errors
stdout
Standard output is empty