답안 #736510

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
736510 2023-05-05T20:26:48 Z vjudge1 Pod starim krovovima (COCI20_psk) C++14
50 / 50
1 ms 340 KB
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define lalala ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mod 1000000007
#define N 1005
#define big 1000000000000000007
int main(){
  lalala;
  int n;cin>>n;
  ll int top=0;
  ll int arr[n];
  memset(arr,0,sizeof(arr));
  vector<pair<ll int,int>> v;// volum index
  for(int i=0;i<n;i++){
    ll int a,b;cin>>a>>b;
    top+=a;
    v.push_back({b,i});
  }
  sort(v.begin(),v.end(),greater<>());
  int cev=n;
  for(auto u:v){
    if(top==0)break;
    ll int vol=u.first,indek=u.second;
    cev--;
    if(vol>=top){
      arr[indek]=top;
      top=0;break;
    }
    top-=vol;
    arr[indek]=vol;
  }
  cout<<cev<<endl;
  for(int i=0;i<n;i++){
    cout<<arr[i]<<" ";
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct