답안 #844245

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
844245 2023-09-05T11:47:06 Z vjudge1 Pod starim krovovima (COCI20_psk) C++17
50 / 50
1 ms 348 KB
// clang-format off
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define lg2(x) (63 - __builtin_clzll(x))
#define db cerr << "BREAK\n"
#define fp(...) fprintf(stderr, __VA_ARGS__)
#define rs(a) a.resize(n)
#define hizli cin.tie(0);ios_base::sync_with_stdio(0)
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rep(a, b) for (int a = 0; a < b; a++)
#define af(x) for(auto&a:x)fp("%d ",a);fp("\n")
#define ff first
#define ss second
#define zekochain main
// clang-format on
template <typename... Args> void in(Args &&...args) {
  (std::cin >> ... >> args);
}
const int N = 2e5 + 5, MOD = 1e9 + 7;

struct bab{
  ll li,vol,ind;
  bool operator<(const bab &other){
    return vol < other.vol;
  }
};

int zekochain(){
  int n;
  cin >> n;
  vector<bab> v(n);
  for(int i=0;i<n;i++){
    int a,b;
    cin >> a >> b;
    v[i]={a,-b,i};
  }

  ll sm = 0;
  for(auto&i:v){
    sm+=i.li;
  }
  sort(all(v));
  vector<int> mp(n);
  int i;
  for( i=0;i<n && sm>0;i++){
    mp[v[i].ind]=min(-v[i].vol,sm);
    sm+=v[i].vol;
  }
  cout << n-i << endl;
  for(auto&a:mp){
    cout << a << ' ';
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct