//最小化->最优化DP
//斜率优化不一定是一维DP
//复杂度O（P*M）
//函数同时与j,k相关
#include<bits/stdc++.h>
using namespace std;
#define go(i,a,b) for(int i=(a);i<=(b);++(i))
#define com(i,a,b) for(int i=(a);i>=(b);--(i))
#define mem(a,b) memset((a),(b),sizeof(a))
#define inf 0x3f3f3f3f
#define fin freopen("input.txt","r",stdin)
#define fout freopen("output.txt","w",stdout)
#define w first
#define t second
typedef long long ll;
#define int long long
const int maxn=1e5+10;
int n,m,p,d[maxn],A[maxn],t[maxn],sum[maxn],q[3*maxn];
int f[105][maxn];

inline void read(int &x){
    int f=1;char s=getchar();x=0;
    while(!isdigit(s)){
    	if(s=='-') f=-1;s=getchar();
    }
    while(isdigit(s)){
   		x=(x<<3)+(x<<1)+s-'0';s=getchar();
    }
    x*=f;
}//读入优化

signed main()
{
    //fin;
    scanf("%lld%lld%lld",&n,&m,&p);
    go(i,2,n) read(d[i]),d[i]+=d[i-1];
    go(i,1,m){
    	int p;
    	read(p),read(t[i]);
    	A[i]=t[i]-d[p];//最早出发时间
	}
	sort(A+1,A+m+1);
	go(i,1,m) sum[i]=sum[i-1]+A[i];
	mem(f,0x3f);
	f[0][0]=0;
	int l,r;
	go(i,1,p){
		q[l=r=1]=0;
		go(j,1,m){
			while(l<r&&f[i-1][q[l+1]]+sum[q[l+1]]-f[i-1][q[l]]-sum[q[l]]<=A[j]*(q[l+1]-q[l]))
			l++;
			f[i][j]=min(f[i][j],f[i-1][q[l]]+j*A[j]-q[l]*A[j]-sum[j]+sum[q[l]]);
			while(l<r&&(f[i-1][j]+sum[j]-f[i-1][q[r]]-sum[q[r]])*(q[r]-q[r-1])<=(j-q[r])*(f[i-1][q[r]]+sum[q[r]]-f[i-1][q[r-1]]-sum[q[r-1]]))
			r--;
			q[++r]=j;
		}
	}
	int ans=1e18;
	go(i,1,p) ans=min(ans,f[i][m]);
	printf("%lld",ans);
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cctype>
#define maxn 30010
using namespace std;
template<typename T>
inline void read(T &x)
{
	int f=1;
	x=0;
	char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-')
			f=-1;
		ch=getchar();
	}
	while(isdigit(ch))
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	x=x*f;
}
int n,m,p,d[maxn],a[maxn];
int f[110][maxn],q[maxn];
int sum[maxn],s[maxn];
int g[maxn];
int l,r;

int main()
{
	read(n),read(m),read(p);
	memset(f,0x3f,sizeof(f));
	for(int i=2;i<=n;i++)
	{
		int x;
		read(x);
		d[i]=d[i-1]+x;
	}
	for(int i=1;i<=m;i++)
	{
		int x,y;
		read(x),read(y);
		a[i]=y-d[x];
	}
	sort(a+1,a+m+1);
	for(int i=1;i<=m;i++)
		s[i]=s[i-1]+a[i];//处理每只猫会对应的等待时间
	f[0][0]=0;
	for(int i=1;i<=p;i++)
	{
		for(int j=1;j<=m;j++)
			g[j]=f[i-1][j]+s[j];// 处理y
		l=r=1;
		q[1]=0;
		for(int j=1;j<=m;j++)
		{
			while(l<r&&g[q[l+1]]-g[q[l]]<=a[j]*(q[l+1]-q[l]))
				l++;
			f[i][j]=min(f[i-1][j],g[q[l]]+a[j]*(j-q[l])-s[j]);
			if(g[j]>=0x3f3f3f3f3f3f3fll) continue;
			while(l<r&&(g[j]-g[q[r]])*(q[r]-q[r-1])
			<(g[q[r]]-g[q[r-1]])*(j-q[r]))// 满足凸 单调增k
				r--;
			q[++r]=j;
		}
	}
	printf("%d",f[p][m]);
	return 0;
}


#include<iostream>
#include<cstring>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<set>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
int side,l,r;
ll n, m, p, dis[200002], temp, temp1, cat[100003], sum[100003];
ll dp[2][100002];
int id[100002];
bool cmp1(int idx, int idy,int standard) {
	return (dp[1 ^ side][idy] + sum[idy] - dp[1 ^ side][idx] - sum[idx] + (idx - idy) * cat[standard] <= 0);
}

bool cmp2(int idx, int idy, int idz) {
	return ((idy - idx) * (dp[1 ^ side][idz] + sum[idz] - dp[1 ^ side][idy] - sum[idy]) <= (idz - idy) * (dp[1 ^ side][idy] + sum[idy] - dp[1 ^ side][idx] - sum[idx]));
}

int main() {

		cin >> n >> m >> p;
		dis[0] = 0;
		for (int i = 1; i < n; ++i) {
			scanf("%lld", &temp);
			dis[i] = dis[i - 1] + temp;
		}
		for (int i = 0; i < m; ++i) {
			scanf("%lld%lld", &temp, &temp1);
			cat[i] = temp1-dis[temp - 1];
		}
		if (m <= p) {
			cout << 0 << endl;
			return 0;
		}
		sort(cat, cat + m);
		sum[0] = cat[0];
		for (int i = 1; i < m; ++i)sum[i] = sum[i - 1] + cat[i];
		memset(dp, 0, sizeof dp);
		side = 1;
		for (int persons = 1; persons <= p; ++persons) {
			side ^= 1;
			if (persons > 1) {
				l = 0, r = 1, id[0] = persons - 2;
			}
			for (int cats = 0; cats < persons; cats++)dp[side][cats] = 0;
			for (int cats = persons; cats < m; ++cats) {
				if (persons == 1) {
					dp[side][cats] = (cats + 1) * cat[cats] - sum[cats];
					continue;
				}

				while (r - l > 1) {
					if (cmp2(id[r - 2], id[r - 1], cats - 1)) {
						--r;
					}
					else break;
				}
				id[r++] = cats - 1;
				while (r - l > 1 && cmp1(id[l], id[l + 1],cats)) ++l;
				dp[side][cats] = dp[1 ^ side][id[l]] + sum[id[l]] - sum[cats] + (cats - id[l]) * cat[cats];

			}
		}
		cout << dp[side][m - 1];

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=101000;
int n,m,p;
ll f[110][N],t[N],d[N],sum[N],inf;
//f[i][j]表示前i个铲屎官,带回了j只小猫
//f[i][j]=f[i-1][k]+t[j]*(j-k)-(sum[j]-sum[k])
//k=t[j]
//x=k
//b=f[i][j]-t[j]*j+sum[j]
//y=sum[k]+f[i-1][k]
ll g[N];//y部分
int q[N];

void solve(){
	memset(f,0x3f,sizeof(f));//longlong型8个字节
	inf=f[0][0];
//	printf("%lld ",inf);
	f[0][0]=0;
	for(int i=1;i<=p;++i){
		int head=1,tail=0;
		q[++tail]=0;//0也是决策点
		for(int j=1;j<=m;++j)g[j]=f[i-1][j]+sum[j];
		for(int j=1;j<=m;++j){
			while(head<tail&&g[q[head+1]]-g[q[head]]<=t[j]*(q[head+1]-q[head]))++head;//找最优决策点
			f[i][j]=min(f[i-1][j],g[q[head]]+t[j]*(j-q[head])-sum[j]);
//			if(g[j]>=inf)continue;//数据大小越界
 if(g[j]>=0x3f3f3f3f3f3f3f3fll) continue;
			while(head<tail&&(g[j]-g[q[tail]])*(q[tail]-q[tail-1])<=(g[q[tail]]-g[q[tail-1]])*(j-q[tail]))--tail;
			q[++tail]=j;
		}
	}
//	for(int i=1;i<=p;i++){
//        for(int j=1;j<=m;j++) g[j]=f[i-1][j]+sum[j];
//        int head=1,tail=1; q[1]=0; //注意斜率优化要从tail=1写起，且要写q[1]=0
//        for(int j=1;j<=m;j++){ //[化除为乘]避免比较的误差产生
//            while(head<tail&&g[q[head+1]]-g[q[head]]
//                <=t[j]*(q[head+1]-q[head])) head++;
//            f[i][j]=min(f[i-1][j],g[q[head]]+t[j]*(j-q[head])-sum[j]);
//            //↑↑↑用min{f[i-1][k]+s[k]+a[j]*(j-k)-s[j])};更新答案
//            if(g[j]>=0x3f3f3f3f3f3f3f3fll) continue; //超界
//            while(head<tail&&(g[j]-g[q[tail]])*(q[tail]-q[tail-1])
//                <=(g[q[tail]]-g[q[tail-1]])*(j-q[tail])) tail--;
//            q[++tail]=j; //新元素入队
//        }
//    }
	printf("%lld",f[p][m]);
}

int main(){
//	freopen("t.in","r",stdin);
	scanf("%d%d%d",&n,&m,&p);
	for(int i=2;i<=n;++i){
		scanf("%lld",&d[i]);
		d[i]+=d[i-1];
	}
	int x;
	for(int i=1;i<=m;++i){
		scanf("%d%lld",&x,&t[i]);
		t[i]-=d[x];//t[i]最终记录要带回这只小猫,铲屎官的最早出发时间
	}
	sort(t+1,t+m+1);
	for(int i=1;i<=m;++i)sum[i]=sum[i-1]+t[i];
	solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MX = 100010;
ll d[MX] ,t[MX] ,S[MX];
int q[101][MX];
ll dp[101][MX];
int hd[MX] ,tl[MX];

double Slope(int i ,int j1 ,int j2){
    return (1.0 * S[j1] + dp[i][j1] - S[j2] - dp[i][j2]) / (j1 - j2);
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    int n ,m ,p;
    cin >> n >> m >> p;
    for(int i = 2 ; i <= n ; ++i){
        cin >> d[i];
        d[i] += d[i - 1];
    }
    for(int i = 1 ,x ,p ; i <= m ; ++i){
        cin >> p >> x;
        t[i] = -d[p] + x;
    }
    sort(t + 1 ,t + 1 + m);
    for(int i = 1 ; i <= m ; ++i)
        S[i] = S[i - 1] + t[i];
    for(int i = 1 ; i <= m ; ++i){
        for(int j = 1 ; j <= min(i ,p) ; ++j){
            while(hd[j - 1] < tl[j - 1] && Slope(j - 1 ,q[j - 1][hd[j - 1]] ,q[j - 1][hd[j - 1] + 1]) <= t[i])
                ++hd[j - 1];
            int tr = q[j - 1][hd[j - 1]];
            dp[j][i] = (dp[j - 1][tr] + t[i] * (i - tr) - S[i] + S[tr]);
            while(hd[j] < tl[j] && Slope(j ,q[j][tl[j]] ,i) < Slope(j ,q[j][tl[j] - 1] ,q[j][tl[j]]))
                --tl[j];
            q[j][++tl[j]] = i;
        }
    }
    cout << dp[p][m];
    return 0;
}


///deep dark fantasies
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int dp[100005][105],a[100005],s[100005],ss[100005];
int main(){
	int n,m,p;
	scanf("%d %d %d",&n,&m,&p);
	for(int i=2;i<=n;++i)	scanf("%d",&s[i]),s[i]+=s[i-1];
	for(int i=1;i<=m;++i){
		int x,y;
		scanf("%d %d",&x,&y);
		a[i]=y-s[x];
	}
	sort(a+1,a+m+1);
	for(int i=1;i<=m;++i)	ss[i]=ss[i-1]+a[i];
	memset(dp,0x7f,sizeof(dp)),dp[0][0]=0;
	for(int i=1;i<=m;++i)
		for(int j=1;j<=p;++j)
			for(int k=0;k<i;++k)
				dp[i][j]=min(dp[i][j],dp[k][j-1]+a[i]*(i-k)-ss[i]+ss[k]);
	printf("%d",dp[m][p]);
	return 0;
}


#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
#define N 100005
#define ll long long
ll dp[N][105];
ll n; ll m; ll p;
ll x[N];
ll a[N]; ll b[N];  ll s[N]; ll q[N];  ll tail; ll head;

// dp[i][k]= dp[j][k-1] - s[i]+s[j] + (i-j)*a[i]   j<i

// dp[i][k+1]= dp[j][k] - s[i]+s[j] + (i-j)*a[i]   j<i

//  c(j,k)  dp[j][k]+s[j]
//  d(i)  -s[i]+i*a[i]
//  dp[i][k+1]=c(j,k)+d(i)-a[i]*j   j<i
// j2>j1
// c(j2,k)+d(i)-a[i]*j2  <=  c(j1,k)+d(i)-a[i]*j1
// c(j2,k)-c(j1,k)  <=  a[i]*( j2-j1 )
//  ( c(j2,k)-c(j1,k) ) /  ( j2-j1 ) <=  a[i]
// 斜率单调递增
#define c(j,k)  (dp[j][k]+s[j])
#define d(i)  ( -s[(i)]+(i)*a[(i)] )

double slope(int j1,int j2,int k){
	return 1.0*( c(j2,k)-c(j1,k) ) /  ( j2-j1==0?1e-9:j2-j1 );
}

int main(){
	scanf("%lld %lld %lld",&n,&m,&p);
	for(int i=2;i<=n;++i){  ll tmp; scanf("%lld",&tmp);  x[i]=x[i-1]+tmp;  }
	for(int i=1;i<=m;++i){
		ll tmp; scanf("%lld",&tmp); a[i]=x[tmp];
		scanf("%lld",b+i);
		a[i]=b[i]-a[i];
	}
	sort(a+1,a+1+m);
	if(a[1]<0){
		ll tmp=abs(a[1]);
		for(int i=1;i<=m;++i) a[i]+=tmp;
	}
	//for(int i=1;i<=m;++i) cout<<a[i]<<"  "; cout<<endl;
	for(int i=1;i<=m;++i) s[i]=s[i-1]+a[i];
	for(int i=1;i<=m;++i) dp[i][1]=a[i]*i-s[i];
	//for(int i=1;i<=m;++i) cout<<dp[i][1]<<"  "; cout<<endl;
	p=min(p,m);
	for(int k=1;k<p;++k){
		head=tail=0;
		for(int i=k;i<m;++i){
			// get dp[i][k]
			// upd dp[i+1][k+1]
			while(tail-head>=2&&slope(q[tail-1],i,k)<=slope(q[tail-2],q[tail-1],k)) --tail;

			q[tail++]=i;

			while(tail-head>=2&&slope(q[head],q[head+1],k)<=a[i+1]) ++head;

			dp[i+1][k+1]=c(q[head],k)+d(i+1)-a[i+1]*q[head];

		}
	}
	printf("%lld\n",dp[m][p]);
	return 0;

}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdlib>
#include<ctime>
#include<bitset>
#define ll long long
#define rep(i,a,b) for(register int i=a;i<=b;++i)
#define fd(i,a,b) for(register int i=a;i>=b;--i)
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#define Abs(a) ((a<0)?-(a):(a))
// using namespace std;
namespace io{
	// char buf[1<<17],*p1=buf,*p2=buf;
	// inline int getc(){
	//      return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<17,stdin),p1==p2)?EOF:*p1++;
 //    }
    #define getc() getchar()
    template<class T>
    inline void Read(T &x){
        x=0;T f=1;char c;
        for(c=getc();c<'0'||c>'9';f=((c=='-')?-1:f),c=getc());
        for(;c>='0'&&c<='9';x=x*10+(c^48),c=getc());
        x*=f;
    }
    template<class T>
    inline void write(T a){
        if(a==0){putchar('0');return;}
        if(a<0)putchar('-'),a=-a;
        char c1[120];
        int h=0;
        while(a)c1[++h]=a%10+'0',a/=10;
        for(int i=h;i>=1;i--)putchar(c1[i]);
        return;
    }
    template<class T>
    inline void write_(T a){write(a);putchar(' ');}
    template<class T>
    inline void writeln(T a){write(a);putchar('\n');}
}
using namespace io;
template<class T>
inline T gcd(T a,T b){return a==0?b:gcd(b%a,a);}
template<class T>
inline T lcm(T a,T b){return 1ll*a/gcd(a,b)*b;}
/*----------------------------------------------------------------------*/
const int N = 1e5 + 9;
int n, m, p, q[N];
ll dp[109][N], dis[N], sum[N], a[N];

int main(){
    Read(n);Read(m);Read(p);
    rep(i,2,n){
        int d;Read(d);
        dis[i] = dis[i - 1] + d;
    }
    rep(i,1,m){
        int h, t;
        Read(h);Read(t);
        a[i] = t - dis[h];
    }
    std::sort(a + 1, a + 1 + m);
    rep(i,1,m) sum[i] = sum[i - 1] + a[i];
    memset(dp, 0x3f, sizeof(dp));
    rep(i,0,p) dp[i][0] = 0;
    rep(i,1,p){
        int l = 1, r = 1;
        memset(q, 0, sizeof(q));
        rep(j,1,m){
            while (l < r && (dp[i - 1][q[l + 1]] - dp[i - 1][q[l]]) <= a[j] * (q[l + 1] - q[l])) ++l;
            dp[i][j] = dp[i - 1][q[l]] + a[j] * (j - q[l]) - (sum[j] - sum[q[l]]);
            while (l < r && (dp[i - 1][q[r]] + sum[q[r]] - dp[i - 1][q[r - 1]] - sum[q[r - 1]]) * (j - q[r]) >= (dp[i - 1][j] + sum[j] - dp[i - 1][q[r]] - sum[q[r]]) * (q[r] - q[r - 1])) --r;
            q[++r] = j;
        }
    }
    writeln(dp[p][m]);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
int n,m,p,q[100010];
int s[100010],head=1,tail=1;
ll t[100010],sumt[100010],f[105][100010],ans;
ll Y(int num,int a){
	return f[num][a]+sumt[a];
}
int main(){
//	freopen("125.txt","r",stdin);
	scanf("%d%d%d",&n,&m,&p);
	for(int i=2;i<=n;i++){
		scanf("%d",&s[i]);
		s[i]=s[i-1]+s[i];
	}
	for(int i=1;i<=m;i++){
		int x,w;
		scanf("%d%d",&x,&w);
		t[i]=w-s[x];
	}
	sort(t+1,t+m+1);
	for(int i=1;i<=m;i++){
		sumt[i]=sumt[i-1]+t[i];
	}
    for(int i=1;i<=m;i++){
    	f[1][i]=t[i]*i-sumt[i];
	}
	ans=f[1][m];
	for(int i=2;i<=p;i++){
		head=1,tail=1;
		for(int j=1;j<=m;j++){
			while(head<tail&&(Y(i-1,q[head+1])-Y(i-1,q[head]))<=
			t[j]*(q[head+1]-q[head]))head++;
			int k=q[head];
			f[i][j]=f[i-1][k]+t[j]*(j-k)-(sumt[j]-sumt[k]);
			while(head<tail&&(Y(i-1,q[tail-1])-Y(i-1,j))*(q[tail-1]-q[tail])<=
			(Y(i-1,q[tail-1])-Y(i-1,q[tail]))*(q[tail-1]-j))tail--;
			q[++tail]=j;
		}
		ans=min(ans,f[i][m]);
	}
//	f[i-1][k] + s[k]  = t[j] * k - t[j] * j + s[j] + f[i][j];
	printf("%lld",ans);
}


#include<algorithm>
#include<cstring>
#include<cstdio>
#define ll long long
#define qwq 100007
int n,m,p;
int d[qwq];
ll t[qwq];
ll sum_t[qwq];
ll dp[107][qwq];
int que[qwq];
int l=1,r=1;
inline int X(int i){
	return i;
}
inline int Y(int i,int k){
	return dp[k][i]+sum_t[i];
}
inline double tan_(int i,int j,int k){
	if(X(i)==X(j))return ((double)(Y(i,k)-Y(j,k)))/(1e-10);
	return ((double)(Y(i,k)-Y(j,k)))/((double)(X(i)-X(j)));
}
void work(int i,int k){
	while(r>l&&tan_(que[l+1],que[l],k-1)<=t[i])++l;
	int j=que[l];
	dp[k][i]=dp[k-1][j]+t[i]*(i-j)-(sum_t[i]-sum_t[j]);
	while(r>l&&tan_(que[r],que[r-1],k-1)>=tan_(i,que[r-1],k-1))--r;
	que[++r]=i;
}
int main(){
//	freopen("qwq.txt","r",stdin);
	scanf("%d%d%d",&n,&m,&p);
	for(int i=2;i<=n;++i){
		scanf("%d",&d[i]);
		d[i]+=d[i-1];
	}
	for(int i=1;i<=m;++i){
		int h;
		scanf("%d%lld",&h,&t[i]);
		t[i]-=d[h];
	}
	std::sort(t+1,t+m+1);

//	for(int i=1;i<=m;++i)printf("%lld ",t[i]);
//	putchar('\n');

	for(int i=1;i<=m;++i)sum_t[i]=sum_t[i-1]+t[i];
	for(int i=1;i<=m;++i){
		dp[1][i]=i*t[i]-sum_t[i];
	}
	for(int k=2;k<=p;++k){
		l=r=1;
		for(int i=1;i<=m;++i){
			work(i,k);
		}
	}
	ll ans=dp[1][m];
	for(int i=2;i<=p;++i)ans=std::min(ans,dp[i][m]);
	printf("%lld\n",ans);
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <iostream>
using namespace std;

#define rg register
#define il inline
#define MX (100000 + 5)
#define ll long long

ll d[MX] ,t[MX] ,S[MX];
int q[101][MX];
ll dp[101][MX];
int hd[MX] ,tl[MX];

double Slope(int i ,int j1 ,int j2){
    return (1.0 * S[j1] + dp[i][j1] - S[j2] - dp[i][j2]) / (j1 - j2);
}

int main(){
    int n ,m ,p;
    cin >> n >> m >> p;
    if(p >= m)  return puts("0") ,0;
    for(int i = 2 ; i <= n ; ++i){
        cin >> d[i];
        d[i] += d[i - 1];
    }
    for(int i = 1 ,x ,p ; i <= m ; ++i){
        cin >> p >> x;
        t[i] = -d[p] + x;
    }
    sort(t + 1 ,t + 1 + m);
    for(int i = 1 ; i <= m ; ++i)
        S[i] = S[i - 1] + t[i];
    for(int i = 1 ; i <= m ; ++i){
        for(int j = 1 ; j <= min(i ,p) ; ++j){
            while(hd[j - 1] < tl[j - 1] && Slope(j - 1 ,q[j - 1][hd[j - 1]] ,q[j - 1][hd[j - 1] + 1]) <= t[i])
                ++hd[j - 1];
            int tr = q[j - 1][hd[j - 1]];
            dp[j][i] = (dp[j - 1][tr] + t[i] * (i - tr) - S[i] + S[tr]);
            while(hd[j] < tl[j] && Slope(j ,q[j][tl[j]] ,i) < Slope(j ,q[j][tl[j] - 1] ,q[j][tl[j]]))
                --tl[j];
            q[j][++tl[j]] = i;
        }
    }
    cout << dp[p][m];
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define LL long long
#define M 100005
const LL INF = 0x3f3f3f3f;

int n, m, p, q[M], head, tail;
LL d[M], a[M], sum[M], f[105][M];

LL slope (LL i, LL j){
    return f[i - 1][j] + sum[j];
}
int main (){
    scanf ("%d %d %d", &n, &m, &p);
    for (int i = 2; i <= n; i ++){
        scanf ("%lld", &d[i]);
        d[i] += d[i - 1];
    }
    for (int i = 1; i <= m; i ++){
        LL h, t;
        scanf ("%lld %lld", &h, &t);
        a[i] = d[h] - t;
    }
    sort (a + 1, a + 1 + m);
    for (int i = 1; i <= m; i ++)
        sum[i] = sum[i - 1] + a[i];
    memset (f, INF, sizeof f);
    f[0][0] = 0;
    for (int i = 1; i <= p; i ++){
        head = 1, tail = 0;
        for (int j = 0; j <= m; j ++){
            while (head < tail && slope (i, q[head + 1]) - slope (i, q[head]) <= a[j] * 1ll * (q[head + 1] - q[head]))
                head ++;
            if (head <= tail)
                f[i][j] = slope (i, q[head]) + a[j] * (j - q[head]) - sum[j];
            while (head < tail && (slope (i, j) - slope(i, q[tail])) * 1ll * (q[tail] - q[tail - 1]) <= (slope (i, q[tail]) + slope (i, q[tail - 1])) * 1ll * (j - q[tail]))
                tail --;
            q[++ tail] = j;
        }
    }
    printf ("%lld\n", f[p][m]);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
 printf("3");
 return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,k;
	scanf("%lld %lld",&n,&k);
	if(n>k*(k-1))
	{
		printf("NO");
		return 0;
	}
	else
	{
		printf("YES\n");
	}
	int i,j;
	int cnt=0;
	int save1,save2;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=k;j++)
		{
			if(j==i)
			{
				if(i!=save1&&j+1!=save2)
				{
					printf("%d %d\n",i,++j);
					save1=i;save2=j;
				}
				else
				{
					printf("%d %d\n",++j,i);
					save1=j;save2=i;
				}
			}
			else
			{
				if(i!=save1&&j!=save2)
				{
					printf("%d %d\n",i,j);
					save1=i;save2=j;
				}
				else
				{
					printf("%d %d\n",j,i);
					save1=j;save2=i;
				}
			}
			cnt++;
			if(cnt==n)
			{
				return 0;
			}
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,k;
	scanf("%lld %lld",&n,&k);
	if(n>k*(k-1))
	{
		printf("NO");
		return 0;
	}
	int i,j;
	int cnt=0;
	bool flag=true;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=k;j++)
		{
			if(j==i)
			{
				if(flag)
				printf("%d %d\n",i,++j);
				else
				printf("%d %d\n",++j,i);
			}
			else
			{
				if(flag)
				printf("%d %d\n",i,j);
				else
				printf("%d %d\n",j,i);
			}
			flag=!flag;
			cnt++;
			if(cnt==n)
			{
				return 0;
			}
		}
	}
	return 0;
}


#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std ;
#define ll long long
const int MOD = 1e9 + 7 ;
const int MAXN = 2e5 + 10;
int n , k;
int main() {
    scanf("%d%d" , &n , &k);
    if(k * (k - 1) < n) printf("NO\n");
    else {
        printf("YES\n");
        int a = 1 , b = 2;
        for(int i = 0 ; i < n ; i++) {
            printf("%d %d\n" , a , b);
            if(i++ < n) printf("%d %d\n" , b++ , a);
            if(b > k) {
                a++;
                b = a + 1;
            }
        }
    }
    return 0;
}


#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std ;
#define ll long long
const int MOD = 1e9 + 7 ;
const int MAXN = 2e5 + 10;
ll n , k;
int main() {
    scanf("%lld%lld" , &n , &k);
    if(k * (k - 1) < n) printf("NO\n");
    else {
        printf("YES\n");
        int a = 1 , b = 2;
        for(int i = 0 ; i < n ; i++) {
            printf("%d %d\n" , a , b);
            if(i++ < n) printf("%d %d\n" , b++ , a);
            if(b > k) {
                a++;
                b = a + 1;
            }
        }
    }
    return 0;
}


#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std ;
#define ll long long
const int MOD = 1e9 + 7 ;
const int MAXN = 2e5 + 10;
ll n , k;
int main() {
    scanf("%lld%lld" , &n , &k);
    if(k * (k - 1) < n) printf("NO\n");
    else {
        printf("YES\n");
        int a = 1 , b = 2;
        for(int i = 0 ; i < n ; ++i) {
            printf("%d %d\n" , a , b);
            if(++i < n) printf("%d %d\n" , b++ , a);
            if(b > k) {
                ++a;
                b = a + 1;
            }
        }
    }
    return 0;
}


#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std ;
#define ll long long
const int MOD = 1e9 + 7 ;
const int MAXN = 2e5 + 10;
int n , k;
int main() {
    scanf("%d%d" , &n , &k);
    if(k * (k - 1) < n) printf("NO\n");
    else {
        printf("YES\n");
        int a = 1 , b = 2;
        for(int i = 0 ; i < n ; ++i) {
            printf("%d %d\n" , a , b);
            if(++i < n) printf("%d %d\n" , b++ , a);
            if(b > k) {
                ++a;
                b = a + 1;
            }
        }
    }
    return 0;
}


#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std ;
#define ll long long
const int MOD = 1e9 + 7 ;
const int MAXN = 2e5 + 10;
int n , k;
int main() {
    scanf("%d%d" , &n , &k);
    if(k * (k - 1) < n) printf("NO\n");
    else {
        printf("YES\n");
        int a = 1 , b = 2;
        for(int i = 0 ; i < n ; i++) {
            if(b == a) b++;
            printf("%d %d\n" , a , b);
            b++;
            if(b > k) {
                a++;
                b = 1;
            }
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define fast_io ios_base::sync_with_stdio(0); //cin.tie(0);
#define ll long long
#define ld long double
#define pb push_back
#define loop(i,n) for(i=1;i<=n;i++)
#define loon(i,n) for(i=n;i>0;i--)
#define pii pair< int,int >
#define pll pair< ll,ll >
#define vii vector< int >
#define vll vector< ll >
#define vss vector< string >
#define vdd vector< double >
#define vpi vector< pii >
#define vpl vector< pll >
#define vvi vector< vii >
#define vvl vector< vll >
#define PQ priority_queue
#define MX 10000005
#define mod 1000000007
#define INF 10000000000000000
#define EPS 1e-12

/* Special functions:
        find_by_order(k) --> returns iterator to the kth largest element counting from 0
        order_of_key(val) --> returns the number of items in a set that are strictly smaller than our item
*/

typedef tree<
pii(ll,ll),					// type long long
null_type,
less<pii(ll,ll)>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

struct compare{
    bool operator() (ll a, ll b)
    {
        return a>b;
    }
};

int main()
{

    fast_io;
    ll n,m,t,i,j,k,a,b,c,cs=1;
    //freopen(input.txt, r, stdin);
    //freopen(output.txt, w, stdout);

    cin>> n >> k;
    if(k*k-k<n){
        cout<< "NO\n";
        return 0;
    }

    vpl res;
    map<pll,bool>ok;
    a=b=-1;
    ll cnt=0;
    for(i=2;i<=k and n;i++){
        ll x=1,y=i;
        while(x<=k and y<=k){
            if(!n)
                break;
            if(res.size()==0)
                res.push_back({x,y});
            else if(res.back().first!=x and res.back().second!=y)
                res.push_back({x,y});
            else
                a=x,b=y;
            x++,y++;
            n--;
        }
        y=1,x=i;
        while(x<=k and y<=k){
            if(!n)
                break;
            if(res.size()==0)
                res.push_back({x,y});
            else if(res.back().first!=x and res.back().second!=y)
                res.push_back({x,y});
            else
                a=x,b=y;
            x++,y++;
            n--;
        }
    }

    cout<< "YES\n";
    if(a!=-1 and b!=-1){
        auto p=res[0];
        ll x=-1,y=-1;
        if(a!=p.first and b!=p.second)
            cout<< a << ' ' << b << "\n",a=b=-1,cnt++;
    }

    for(i=0;i<res.size();i++){
        auto p=res[i];
        cout<< p.first << ' ' << p.second << "\n";cnt++;

        if(a!=-1 and b!=-1){
            ll x=-1,y=-1;
            if(i+1<res.size())
                x=res[i+1].first,y=res[i+1].second;
            if(a!=x and a!=p.first and b!=y and b!=p.second)
                cout<< a << ' ' << b << "\n",a=b=-1,cnt++;
        }
    }

    if(a!=-1 and b!=-1){
        auto p=res[res.size()-1];
        ll x=-1,y=-1;
        if(a!=x and a!=p.first and b!=y and b!=p.second)
            cout<< a << ' ' << b << "\n",a=b=-1,cnt++;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define fast_io ios_base::sync_with_stdio(0); //cin.tie(0);
#define ll long long
#define ld long double
#define pb push_back
#define loop(i,n) for(i=1;i<=n;i++)
#define loon(i,n) for(i=n;i>0;i--)
#define pii pair< int,int >
#define pll pair< ll,ll >
#define vii vector< int >
#define vll vector< ll >
#define vss vector< string >
#define vdd vector< double >
#define vpi vector< pii >
#define vpl vector< pll >
#define vvi vector< vii >
#define vvl vector< vll >
#define PQ priority_queue
#define MX 10000005
#define mod 1000000007
#define INF 10000000000000000
#define EPS 1e-12

/* Special functions:
        find_by_order(k) --> returns iterator to the kth largest element counting from 0
        order_of_key(val) --> returns the number of items in a set that are strictly smaller than our item
*/

typedef tree<
pii(ll,ll),					// type long long
null_type,
less<pii(ll,ll)>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

struct compare{
    bool operator() (ll a, ll b)
    {
        return a>b;
    }
};

int main()
{

    fast_io;
    ll n,m,t,i,j,k,a,b,c,cs=1;
    //freopen(input.txt, r, stdin);
    //freopen(output.txt, w, stdout);

    cin>> n >> k;
    if(k*k-k<n){
        cout<< "NO\n";
        return 0;
    }

    vpl res;
    map<pll,bool>ok;
    a=b=-1;
    for(i=2;i<=k and n;i++){
        ll x=1,y=i;
        while(x<=k and y<=k){
            if(!n)
                break;
            if(res.size()==0)
                res.push_back({x,y});
            else if(res.back().first!=x and res.back().second!=y)
                res.push_back({x,y});
            else
                a=x,b=y;
            x++,y++;
            n--;
        }
        y=1,x=i;
        while(x<=k and y<=k){
            if(!n)
                break;
            if(res.size()==0)
                res.push_back({x,y});
            else if(res.back().first!=x and res.back().second!=y)
                res.push_back({x,y});
            else
                a=x,b=y;
            x++,y++;
            n--;
        }
    }

    cout<< "YES\n";
    for(i=0;i<res.size();i++){
        auto p=res[i];
        cout<< p.first << ' ' << p.second << "\n";

        if(a!=-1 and b!=-1){
            ll x=-1,y=-1;
            if(i+1<res.size())
                x=res[i+1].first,y=res[i].second;
            if(a!=x and a!=p.first and b!=y and b!=p.second)
                cout<< a << ' ' << b << "\n",a=b=-1;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define fast_io ios_base::sync_with_stdio(0); //cin.tie(0);
#define ll long long
#define ld long double
#define pb push_back
#define loop(i,n) for(i=1;i<=n;i++)
#define loon(i,n) for(i=n;i>0;i--)
#define pii pair< int,int >
#define pll pair< ll,ll >
#define vii vector< int >
#define vll vector< ll >
#define vss vector< string >
#define vdd vector< double >
#define vpi vector< pii >
#define vpl vector< pll >
#define vvi vector< vii >
#define vvl vector< vll >
#define PQ priority_queue
#define MX 10000005
#define mod 1000000007
#define INF 10000000000000000
#define EPS 1e-12

/* Special functions:
        find_by_order(k) --> returns iterator to the kth largest element counting from 0
        order_of_key(val) --> returns the number of items in a set that are strictly smaller than our item
*/

typedef tree<
pii(ll,ll),					// type long long
null_type,
less<pii(ll,ll)>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

struct compare{
    bool operator() (ll a, ll b)
    {
        return a>b;
    }
};

int main()
{

    fast_io;
    ll n,m,t,i,j,k,a,b,c,cs=1;
    //freopen(input.txt, r, stdin);
    //freopen(output.txt, w, stdout);

    cin>> n >> k;
    if(k*k-k<n){
        cout<< "NO\n";
        return 0;
    }

    vpl res;
    map<pll,bool>ok;
    for(i=2;i<=k and n;i++){
        ll x=1,y=i;
        while(x<=k and y<=k){
            if(!n)
                break;
            res.push_back({x,y});
            x++,y++;
            n--;
        }
    }
    for(i=2;i<=k and n;i++){
        ll y=1,x=i;
        while(x<=k and y<=k){
            if(!n)
                break;
            res.push_back({x,y});
            x++,y++;
            n--;
        }
    }

    cout<< "YES\n";
    for(auto p:res){
        cout<< p.first << ' ' << p.second << "\n";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define fast_io ios_base::sync_with_stdio(0); //cin.tie(0);
#define ll long long
#define ld long double
#define pb push_back
#define loop(i,n) for(i=1;i<=n;i++)
#define loon(i,n) for(i=n;i>0;i--)
#define pii pair< int,int >
#define pll pair< ll,ll >
#define vii vector< int >
#define vll vector< ll >
#define vss vector< string >
#define vdd vector< double >
#define vpi vector< pii >
#define vpl vector< pll >
#define vvi vector< vii >
#define vvl vector< vll >
#define PQ priority_queue
#define MX 10000005
#define mod 1000000007
#define INF 10000000000000000
#define EPS 1e-12

/* Special functions:
        find_by_order(k) --> returns iterator to the kth largest element counting from 0
        order_of_key(val) --> returns the number of items in a set that are strictly smaller than our item
*/

typedef tree<
pii(ll,ll),					// type long long
null_type,
less<pii(ll,ll)>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

struct compare{
    bool operator() (ll a, ll b)
    {
        return a>b;
    }
};

int main()
{

    fast_io;
    ll n,m,t,i,j,k,a,b,c,cs=1;
    //freopen(input.txt, r, stdin);
    //freopen(output.txt, w, stdout);

    cin>> n >> k;
    if(k*k-k<n){
        cout<< "NO\n";
        return 0;
    }

    vpl res;
    map<pll,bool>ok;
    a=b=-1;
    ll cnt=0;
    for(i=2;i<=k and n;i++){
        ll x=1,y=i;
        while(x<=k and y<=k){
            if(!n)
                break;
            if(res.size()==0)
                res.push_back({x,y});
            else if(res.back().first!=x and res.back().second!=y)
                res.push_back({x,y});
            else
                a=x,b=y;
            x++,y++;
            n--;
        }
        y=1,x=i;
        while(x<=k and y<=k){
            if(!n)
                break;
            if(res.size()==0)
                res.push_back({x,y});
            else if(res.back().first!=x and res.back().second!=y)
                res.push_back({x,y});
            else
                a=x,b=y;
            x++,y++;
            n--;
        }
    }

    cout<< "YES\n";
    for(i=0;i<res.size();i++){
        auto p=res[i];
        cout<< p.first << ' ' << p.second << "\n";cnt++;

        if(a!=-1 and b!=-1){
            ll x=-1,y=-1;
            if(i+1<res.size())
                x=res[i+1].first,y=res[i+1].second;
            if(a!=x and a!=p.first and b!=y and b!=p.second)
                cout<< a << ' ' << b << "\n",a=b=-1,cnt++;
        }
    }

    if(a!=-1 and b!=-1){
        auto p=res[res.size()-1];
        ll x=-1,y=-1;
        if(a!=x and a!=p.first and b!=y and b!=p.second)
            cout<< a << ' ' << b << "\n",a=b=-1,cnt++;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define fast_io ios_base::sync_with_stdio(0); //cin.tie(0);
#define ll long long
#define ld long double
#define pb push_back
#define loop(i,n) for(i=1;i<=n;i++)
#define loon(i,n) for(i=n;i>0;i--)
#define pii pair< int,int >
#define pll pair< ll,ll >
#define vii vector< int >
#define vll vector< ll >
#define vss vector< string >
#define vdd vector< double >
#define vpi vector< pii >
#define vpl vector< pll >
#define vvi vector< vii >
#define vvl vector< vll >
#define PQ priority_queue
#define MX 10000005
#define mod 1000000007
#define INF 10000000000000000
#define EPS 1e-12

/* Special functions:
        find_by_order(k) --> returns iterator to the kth largest element counting from 0
        order_of_key(val) --> returns the number of items in a set that are strictly smaller than our item
*/

typedef tree<
pii(ll,ll),					// type long long
null_type,
less<pii(ll,ll)>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

struct compare{
    bool operator() (ll a, ll b)
    {
        return a>b;
    }
};

int main()
{

    fast_io;
    ll n,m,t,i,j,k,a,b,c,cs=1;
    //freopen(input.txt, r, stdin);
    //freopen(output.txt, w, stdout);

    cin>> n >> k;
    if(k*k-k<n){
        cout<< "NO\n";
        return 0;
    }

    vpl res;
    map<pll,bool>ok;
    a=b=-1;
    ll cnt=0;
    for(i=2;i<=k and n;i++){
        ll x=1,y=i;
        while(x<=k and y<=k){
            if(!n)
                break;
            if(res.size()==0)
                res.push_back({x,y});
            else if(res.back().first!=x and res.back().second!=y)
                res.push_back({x,y});
            else
                a=x,b=y;
            x++,y++;
            n--;
        }
        y=1,x=i;
        while(x<=k and y<=k){
            if(!n)
                break;
            if(res.size()==0)
                res.push_back({x,y});
            else if(res.back().first!=x and res.back().second!=y)
                res.push_back({x,y});
            else
                a=x,b=y;
            x++,y++;
            n--;
        }
    }

    cout<< "YES\n";
    for(i=0;i<res.size();i++){
        auto p=res[i];
        cout<< p.first << ' ' << p.second << "\n";cnt++;

        if(a!=-1 and b!=-1){
            ll x=-1,y=-1;
            if(i+1<res.size())
                x=res[i+1].first,y=res[i+1].second;
            if(a!=x and a!=p.first and b!=y and b!=p.second)
                cout<< a << ' ' << b << "\n",a=b=-1,cnt++;
        }
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;

int main(void)
{
    int n,k;
    scanf("%d %d",&n,&k);
    if(n>k*(k-1))
    {
        printf("NO\n");
        return 0;
    }
    int i=1,j=2;
    printf("Yes\n");
    while(n)
    {
        if(n--)
            printf("%d %d\n",i,j);
        if(n--)
            printf("%d %d\n",j,i);
        j++;
        if(j>k)
        {
            i++;
            j=i+1;
        }
    }
}


#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;

int main(void)
{
    int n,k;
    scanf("%d %d",&n,&k);
    if(n>k*(k-1))
    {
        printf("NO\n");
        return 0;
    }
    int i=1,j=2;
    printf("Yes\n");
    while(n)
    {
        if(n)
        {
            printf("%d %d\n",i,j);
            n--;
        }
        if(n)
        {
            printf("%d %d\n",j,i);
            n--;
        }
        j++;
        if(j>k)
        {
            i++;
            j=i+1;
        }
    }
}


#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;

int main(void)
{
    long long n,k;
    scanf("%lld %lld",&n,&k);
    if(n>k*(k-1))
    {
        printf("NO\n");
        return 0;
    }
    long long i=1,j=2;
    printf("Yes\n");
    while(n)
    {
        if(n)
        {
            printf("%lld %lld\n",i,j);
            n--;
        }
        if(n)
        {
            printf("%lld %lld\n",j,i);
            n--;
        }
        j++;
        if(j>k)
        {
            i++;
            j=i+1;
        }
    }
}


#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;

int main(void)
{
    long long n,k;
    scanf("%lld %lld",&n,&k);
    if(n>k*(k-1))
    {
        printf("NO\n");
        return 0;
    }
    long long i=1,j=2;
    printf("Yes\n");
    while(n)
    {
        if(n)
        {
            printf("%d %d\n",i,j);
            n--;
        }
        if(n)
        {
            printf("%d %d\n",j,i);
            n--;
        }
        j++;
        if(j>k)
        {
            i++;
            j=i+1;
        }
    }
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define ll long long
#define int long long
#define ld double
#define pii pair<int,int>
#define rand() abs((rand()<<15)|rand())
#define randll() abs(((long long)rand()<<30)|rand())
const int MOD = 1'000'000'007;

int n, k, done;
void out(int a, int b) {
	cout << a << " " << b << endl;
	done++;
	if(done==n)
		exit(0);
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long long seed;
	asm("rdtsc" : "=A"(seed));
	srand(seed);

	cin >> n >> k;
	if((k-1)*k < n) {
		cout << "NO" << endl;
		return 0;
	}

	cout << "YES" << endl;

	out(n,1);
	out(1,n);
	for(int offset = 2; offset < n; offset++) {
		for(int i = n, j = offset; j >= 1; i--,j--) {
			out(i,j);
		}
	}
	for(int offset = 2; offset < n; offset++) {
		for(int j = n, i = offset; i >= 1; i--,j--) {
			out(i,j);
		}
	}
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define ll long long
#define int long long
#define ld double
#define pii pair<int,int>
#define rand() abs((rand()<<15)|rand())
#define randll() abs(((long long)rand()<<30)|rand())
const int MOD = 1'000'000'007;

int n, k, done;
void out(int a, int b) {
	cout << a << " " << b << endl;
	done++;
	if(done==n)
		exit(0);
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long long seed;
	asm("rdtsc" : "=A"(seed));
	srand(seed);

	cin >> n >> k;
	if((k-1)*k < n) {
		cout << "NO" << endl;
		return 0;
	}

	cout << "YES" << endl;

	out(k,1);
	out(1,k);
	for(int offset = 2; offset < k; offset++) {
		for(int i = k, j = offset; j >= 1; i--,j--) {
			out(i,j);
		}
	}
	for(int offset = 2; offset < k; offset++) {
		for(int j = k, i = k+1-offset; i >= 1; i--,j--) {
			out(i,j);
		}
	}
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define ll long long
#define int long long
#define ld double
#define pii pair<int,int>
#define rand() abs((rand()<<15)|rand())
#define randll() abs(((long long)rand()<<30)|rand())
const int MOD = 1'000'000'007;

int n, k, done;
void out(int a, int b) {
	cout << a << " " << b << endl;
	done++;
	if(done==n)
		exit(0);
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long long seed;
	asm("rdtsc" : "=A"(seed));
	srand(seed);

	cin >> n >> k;
	if((k-1)*k < n) {
		cout << "NO" << endl;
		return 0;
	}

	cout << "YES" << endl;

	out(k,1);
	out(1,k);
	for(int offset = 2; offset < k; offset++) {
		for(int i = k, j = offset; j >= 1; i--,j--) {
			out(i,j);
		}
	}
	for(int offset = 2; offset < k; offset++) {
		for(int j = offset, i = 1; j <= k; i++,j++) {
			out(i,j);
		}
	}
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define ll long long
#define int long long
#define ld double
#define pii pair<int,int>
#define rand() abs((rand()<<15)|rand())
#define randll() abs(((long long)rand()<<30)|rand())
const int MOD = 1'000'000'007;

int n, k, done;
void out(int a, int b) {
	cout << a << " " << b << endl;
	done++;
	if(done==n)
		exit(0);
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long long seed;
	asm("rdtsc" : "=A"(seed));
	srand(seed);

	cin >> n >> k;
	if((k-1)*k < n) {
		cout << "NO" << endl;
		return 0;
	}

	cout << "YES" << endl;

	out(k,1);
	out(1,k);
	for(int offset = 2; offset < k; offset++) {
		for(int i = k, j = offset; j >= 1; i--,j--) {
			out(i,j);
		}
	}
	for(int offset = 2; offset < k; offset++) {
		for(int j = k, i = offset; i >= 1; i--,j--) {
			out(i,j);
		}
	}
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define ll long long
#define int long long
#define ld double
#define pii pair<int,int>
#define rand() abs((rand()<<15)|rand())
#define randll() abs(((long long)rand()<<30)|rand())
const int MOD = 1'000'000'007;

int n, k, done;
void out(int a, int b) {
	cout << a << " " << b << endl;
	done++;
	if(done==n)
		exit(0);
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long long seed;
	asm("rdtsc" : "=A"(seed));
	srand(seed);

	cin >> n >> k;
	if((k-1)*k < n) {
		cout << "NO" << endl;
		return 0;
	}

	cout << "YES" << endl;

	out(k,1);
	out(1,k);
	for(int offset = 2; offset < k; offset++) {
		for(int i = k, j = offset; j >= 1; i--,j--) {
			out(i,j);
		}
	}
	for(int offset = 2; offset < k; offset--) {
		for(int j = offset, i = 1; j <= k; i++,j++) {
			out(i,j);
		}
	}
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define ll long long
#define int long long
#define ld double
#define pii pair<int,int>
#define rand() abs((rand()<<15)|rand())
#define randll() abs(((long long)rand()<<30)|rand())
const int MOD = 1'000'000'007;

int n, k, done;
void out(int a, int b) {
	cout << a << " " << b << endl;
	done++;
	if(done==n)
		exit(0);
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long long seed;
	asm("rdtsc" : "=A"(seed));
	srand(seed);

	cin >> n >> k;
	if((k-1)*k < n) {
		cout << "NO" << endl;
		return 0;
	}

	cout << "YES" << endl;

	out(k,1);
	out(1,k);
	for(int offset = 2; offset < k; offset++) {
		for(int i = k, j = offset; j >= 1; i--,j--) {
			out(i,j);
		}
	}
	for(int offset = k-1; offset >= 2; offset--) {
		for(int j = k, i = offset; i >= 1; i--,j--) {
			out(i,j);
		}
	}
}


#include <iostream>
#include <vector>

using namespace std;

void fucntion(long long, long long);

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	long long n, k;
	cin >> n >> k;

		if (n > k * (k-1))
		{
			cout << "NO" << endl;
		}
		else
		{
			cout << "YES" << endl;
			fucntion(n, k);
		}

}

void fucntion(long long n, long long k)
{
	int count = 0;
		for (long long s = 0; s < k; s++)
		{
			for (long long i = 0; s < k; i++)
			{
				cout << s + 1 << " " << i + 1 << endl;
				count++;
				if (count > n)
				{
					return;
				}
			}
		}
}


#include <iostream>
#include <vector>

using namespace std;

void fucntion(long long, long long);

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	long long n, k;
	cin >> n >> k;

		if (n > k * (k-1))
		{
			cout << "NO" << endl;
		}
		else
		{
			cout << "YES" << endl;
			fucntion(n, k);
		}

}

void fucntion(long long n, long long k)
{
	int count = 0;
		for (long long s = 0; s < k; s++)
		{
			for (long long i = 0; s < k; i++)
			{
				if (s != i)
				{
					cout << s + 1 << " " << i + 1 << endl;
					count++;
					if (count > n)
					{
						return;
					}
				}
			}
		}
}


#include <iostream>
#include <vector>

using namespace std;

void fucntion(long long, long long);

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	long long n, k;
	cin >> n >> k;

		if (n > k * (k-1))
		{
			cout << "NO" << endl;
		}
		else
		{
			cout << "YES" << endl;
			fucntion(n, k);
		}

}

void fucntion(long long n, long long k)
{
	long long count = 0;
		for (long long s = 0; s < k; s++)
		{
			for (long long i = 0; s < k; i++)
			{
				if (s != i)
				{
					cout << s + 1 << " " << i + 1 << endl;
					count++;
					if (count >= n)
					{
						return;
					}
					cout << i + 1 << " " << s + 1 << endl;
					count++;
					if (count >= n)
					{
						return;
					}

				}
			}
		}
}


#include <iostream>

using namespace std;

void fucntion(long long, long long);

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	long long n, k;
	cin >> n >> k;

		if (n > k * (k-1))
		{
			cout << "NO" << endl;
		}
		else
		{
			cout << "YES" << endl;
			fucntion(n, k);
		}

}

void fucntion(long long n, long long k)
{
	long long count = 0;
		for (long long s = 1; s <= k; s++)
		{
			for (long long i = 1; i <= k; i++)
			{
				if (s != i)
				{
					cout << s << " " << i << endl;
					count++;
					if (count >= n)
					{
						return;
					}
					cout << i << " " << s << endl;
					count++;
					if (count >= n)
					{
						return;
					}

				}
			}
		}
}


#include <iostream>

using namespace std;

void fucntion(long long, long long);

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	long long n, k;
	cin >> n >> k;

		if (n > k * (k-1))
		{
			cout << "NO" << endl;
		}
		else
		{
			cout << "YES" << endl;
			fucntion(n, k);
		}

}

void fucntion(long long n, long long k)
{
	long long count = 0;
		for (long long s = 1; s <= k; s++)
		{
			for (long long i = 1; i <= k; i++)
			{
				if (s != i)
				{
					cout << s + 1 << " " << i + 1 << endl;
					count++;
					if (count >= n)
					{
						return;
					}
					cout << i + 1 << " " << s + 1 << endl;
					count++;
					if (count >= n)
					{
						return;
					}

				}
			}
		}
}


#include <iostream>
#include <vector>

using namespace std;

void fucntion(long long, long long);

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	long long n, k;
	cin >> n >> k;

		if (n > k * (k-1))
		{
			cout << "NO" << endl;
		}
		else
		{
			cout << "YES" << endl;
			fucntion(n, k);
		}

}

void fucntion(long long n, long long k)
{
	int count = 0;
		for (long long s = 0; s < k; s++)
		{
			for (long long i = 0; s < k; i++)
			{
				cout << s + 1 << " " << s + 1 << endl;
				count++;
				if (count > n)
				{
					return;
				}
			}
		}
}


#include <iostream>
#include <vector>

using namespace std;

void fucntion(long long, long long);

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	long long n, k;
	cin >> n >> k;

		if (n > k * (k-1))
		{
			cout << "NO" << endl;
		}
		else
		{
			cout << "YES" << endl;
			fucntion(n, k);
		}

}

void fucntion(long long n, long long k)
{
	int count = 0;
		for (long long s = 0; s < k; s++)
		{
			for (long long i = 0; s < k; i++)
			{
				if (s != i)
				{
					cout << s + 1 << " " << i + 1 << endl;
					count++;
					if (count > n)
					{
						return;
					}
					cout << i + 1 << " " << s + 1 << endl;
				}
			}
		}
}


#include <iostream>

using namespace std;

void fucntion(long long, long long);

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	long long n, k;
	cin >> n >> k;

		if (n > k * (k-1))
		{
			cout << "NO" << endl;
		}
		else
		{
			cout << "YES" << endl;
			fucntion(n, k);
		}

}

void fucntion(long long n, long long k)
{
	long long count = 0;
		for (long long s = 1; s <= k; s++)
		{
			for (long long i = 1; i <= k; i++)
			{
				if (s < i)
				{
					cout << s << " " << i << endl;
					count++;
					if (count >= n)
					{
						return;
					}
					cout << i << " " << s << endl;
					count++;
					if (count >= n)
					{
						return;
					}

				}
			}
		}
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#define int long long
#define pb emplace_back
#define mp make_pair
#define tci(v,i) for(auto i=v.begin();i!=v.end();i++)
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define osit ostream_iterator<int> output (cout," ")
#define pv(x) copy(all(x),output)
#define pa(a) rep(i,0,sizeof(a)/sizeof(a[0]))cout<<a[i]<<" "
#define endl '\n'
#define f first
#define s second
#define PI 3.141592653589793
#define set0(x) memset(x,0,sizeof(x))
#define sort_uniq(c) (sort(c.begin(), c.end()), c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define uniq(a) a.resize(distance(a.begin(), unique(a.begin(), a.end())))
#define dg(x) cout<<#x<<':'<<x<<endl;
#define dg2(x,y) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<endl;
#define dg3(x,y,z) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<endl;
#define dg4(x,y,z,zz) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<' '<<#zz<<':'<<zz<<endl;
using namespace __gnu_pbds;
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
int isPowerof2(int x) { return (x && !(x & x-1)); }

int32_t main(){
	boost;osit;
	int n,k;
	cin>>n>>k;
	int lim=k*(k-1);
	if(n>lim){
		cout<<"NO";
	}else{
		cout<<"YES"<<endl;
		int cnt=0;
		for(int x=1;x<k;x++){
			if(cnt==n)break;
			for(int i=0,j=x;j<k;i++,j++){
				if(cnt==n)break;
				cout<<j+1<<" "<<i+1<<endl;
				cnt++;
			}
			if(cnt==n)break;
			for(int i=k-1,j=k-1-x;j>=0;i--,j--){
				if(cnt==n)break;
				cout<<j+1<<" "<<i+1<<endl;
				cnt++;
			}
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#define int long long
#define pb emplace_back
#define mp make_pair
#define tci(v,i) for(auto i=v.begin();i!=v.end();i++)
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define osit ostream_iterator<int> output (cout," ")
#define pv(x) copy(all(x),output)
#define pa(a) rep(i,0,sizeof(a)/sizeof(a[0]))cout<<a[i]<<" "
#define endl '\n'
#define f first
#define s second
#define PI 3.141592653589793
#define set0(x) memset(x,0,sizeof(x))
#define sort_uniq(c) (sort(c.begin(), c.end()), c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define uniq(a) a.resize(distance(a.begin(), unique(a.begin(), a.end())))
#define dg(x) cout<<#x<<':'<<x<<endl;
#define dg2(x,y) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<endl;
#define dg3(x,y,z) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<endl;
#define dg4(x,y,z,zz) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<' '<<#zz<<':'<<zz<<endl;
using namespace __gnu_pbds;
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
int isPowerof2(int x) { return (x && !(x & x-1)); }

int32_t main(){
	boost;osit;
	int n,k;
	cin>>n>>k;
	int lim=k*(k-1);
	if(n>lim){
		cout<<"NO";
	}else{
		cout<<"YES"<<endl;
		int cnt=0;
		for(int x=1;x<k;x++){
			if(cnt==n)break;
			for(int i=0,j=x;j<k;i++,j++){
				cout<<i+1<<" "<<j+1<<endl;
				cnt++;
			}
			if(cnt==n)break;
			for(int i=x,j=0;i<k;i++,j++){
				cout<<i+1<<" "<<j+1<<endl;
				cnt++;
			}
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#define int long long
#define pb emplace_back
#define mp make_pair
#define tci(v,i) for(auto i=v.begin();i!=v.end();i++)
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define osit ostream_iterator<int> output (cout," ")
#define pv(x) copy(all(x),output)
#define pa(a) rep(i,0,sizeof(a)/sizeof(a[0]))cout<<a[i]<<" "
#define endl '\n'
#define f first
#define s second
#define PI 3.141592653589793
#define set0(x) memset(x,0,sizeof(x))
#define sort_uniq(c) (sort(c.begin(), c.end()), c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define uniq(a) a.resize(distance(a.begin(), unique(a.begin(), a.end())))
#define dg(x) cout<<#x<<':'<<x<<endl;
#define dg2(x,y) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<endl;
#define dg3(x,y,z) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<endl;
#define dg4(x,y,z,zz) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<' '<<#zz<<':'<<zz<<endl;
using namespace __gnu_pbds;
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
int isPowerof2(int x) { return (x && !(x & x-1)); }

int32_t main(){
	boost;osit;
	int n,k;
	cin>>n>>k;
	if(n>(k*(k-1))){
		cout<<"NO";
	}else{
		cout<<"YES"<<endl;
		vii up[k];
		vii down[k];
		for(int i=0;i<k;i++){
			for(int j=0;j<k;j++){
				if(j-i>0)up[j-i].pb(mp(i,j));
				if(i-j>0)down[i-j].pb(mp(i,j));
			}
		}

		vii ans;
		for(int i=1;i<k;i++){
			for(auto el:up[i])ans.pb(el);
			reverse(all(down[i]));
			for(auto el:down[i])ans.pb(el);
		}
		for(int i=0;i<n;i++){
			cout<<ans[i].f+1<<" "<<ans[i].s+1<<endl;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#define int long long
#define pb emplace_back
#define mp make_pair
#define tci(v,i) for(auto i=v.begin();i!=v.end();i++)
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define osit ostream_iterator<int> output (cout," ")
#define pv(x) copy(all(x),output)
#define pa(a) rep(i,0,sizeof(a)/sizeof(a[0]))cout<<a[i]<<" "
#define endl '\n'
#define f first
#define s second
#define PI 3.141592653589793
#define set0(x) memset(x,0,sizeof(x))
#define sort_uniq(c) (sort(c.begin(), c.end()), c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define uniq(a) a.resize(distance(a.begin(), unique(a.begin(), a.end())))
#define dg(x) cout<<#x<<':'<<x<<endl;
#define dg2(x,y) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<endl;
#define dg3(x,y,z) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<endl;
#define dg4(x,y,z,zz) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<' '<<#zz<<':'<<zz<<endl;
using namespace __gnu_pbds;
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
int isPowerof2(int x) { return (x && !(x & x-1)); }

int32_t main(){
	boost;osit;
	int n,k;
	cin>>n>>k;
	int lim=k*(k-1);
	if(n>lim){
		cout<<"NO";
	}else{
		cout<<"YES"<<endl;
		int cnt=0;
		for(int x=1;x<k;x++){
			if(cnt==n)break;
			for(int i=0,j=x;j<k;i++,j++){
				cout<<j+1<<" "<<i+1<<endl;
				cnt++;
			}
			if(cnt==n)break;
			for(int i=k-1,j=k-1-x;j>=0;i--,j--){
				cout<<j+1<<" "<<i+1<<endl;
				cnt++;
			}
		}
	}
	return 0;
}


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

using namespace std;
//using namespace __gnu_pbds;

#define llong long long
#define dlong long double
#define ulong unsigned long long
#define endl '\n'
#define pb push_back
#define F first
#define S second

// CODE CODE CODE CODE CODE CODE CODE CODE CODE

const llong N = 2e5  + 36;
const llong M = 1e5 + 36;
const llong INF = 2e18 + 7;
const llong MOD1 = 987654323;
const llong MOD = 1e9 + 7;
const llong MOD2 = 1e9 + 9;
const int XK[4] = {-1, 0, 1, 0};
const int YK[4] = {0, -1, 0, 1};
const int X[8] = {1, 1, -1, -1, 2, 2, -2, -2};
const int Y[8] = {2, -2, 2, -2, 1, -1, 1, -1};

//tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> st;

mt19937 gen(time(0));

set < int > st[N];
int us[N];

vector < pair < int, int > > ans;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif // LOCAL
    llong n, k;
    cin >> n >> k;
    if (k % 2 == 0) {
        if (k * (k - 1) < n) {
            cout << "NO" << endl;
            return 0;
        }
        cout << "YES" << endl;
        llong now = 1, lst = -1;
        for (int i(1); i <= k; ++i) {
            us[i] = 1;
        }
        while (n--) {
            cout << now << ' ';
            for (int j(us[now]); j <= k; ++j) {
                if (now != j && lst != j && !st[now].count(j)) {
                    if (us[now] == j) {
                        ++us[now];
                    }
                    st[now].insert(j);
                    lst = j;
                    cout << j;
                    break;
                }
            }
            cout << endl;
            ++now;
            if (now > k) {
                now = 1;
            }
        }
    } else {
        if (k * (k - 1) < n) {
            cout << "NO" << endl;
            return 0;
        }
        cout << "YES" << endl;
        if (k == 3) {
            cout << 1 << ' ' <<  3 << endl;
            if (n > 1)
                cout << 2 << ' ' <<  1 << endl;
            if (n > 2)
                cout << 1 << ' ' <<  2 << endl;
            if (n > 3)
                cout << 3 << ' ' <<  1 << endl;
            if (n > 4)
                cout << 2 << ' ' <<  3 << endl;
            if (n > 5)
                cout << 3 << ' ' <<  2 << endl;
            return 0;
        }
        if (k == 5) {
            cout << 1 << ' ' <<  5 << endl;
            if (n > 1)
                cout << 2 << ' ' <<  1 << endl;
            if (n > 2)
                cout << 3 << ' ' <<  5 << endl;
            if (n > 3)
                cout << 4 << ' ' <<  1 << endl;
            if (n > 4)
                cout << 5 << ' ' <<  3 << endl;
            if (n > 5)
                cout << 2 << ' ' <<  4 << endl;
            if (n > 6)
                cout << 1 << ' ' <<  3 << endl;
            if (n > 7)
                cout << 3 << ' ' <<  1 << endl;
            if (n > 8)
                cout << 4 << ' ' <<  2 << endl;
            if (n > 9)
                cout << 5 << ' ' <<  1 << endl;
            if (n > 10)
                cout << 1 << ' ' <<  4 << endl;
            if (n > 11)
                cout << 2 << ' ' <<  3 << endl;
            if (n > 12)
                cout << 3 << ' ' <<  4 << endl;
            if (n > 13)
                cout << 4 << ' ' <<  3 << endl;
            if (n > 14)
                cout << 5 << ' ' <<  4 << endl;
            if (n > 15)
                cout << 1 << ' ' <<  2 << endl;
            if (n > 16)
                cout << 2 << ' ' <<  5 << endl;
            if (n > 17)
                cout << 3 << ' ' <<  2 << endl;
            if (n > 18)
                cout << 4 << ' ' <<  5 << endl;
            if (n > 19)
                cout << 5 << ' ' <<  2 << endl;
            return 0;
        }
        llong now = 1, lst = -1;
        for (int i(1); i <= k; ++i) {
            us[i] = 1;
        }
        llong kk = n, nn = n;
        bool bad = false;
        while (n > 0 || now <= k) {
            --n;
            if (now > k) {
                now = 1;
            }
            ans.pb({0, k});
            ans.back().F = now;
            //cout << now << ' ';
            bool f = true;
            for (int j(us[now]); j <= k; ++j) {
                if (now != j && lst != j && !st[now].count(j)) {
                    if (us[now] == j) {
                        ++us[now];
                    }
                    st[now].insert(j);
                    lst = j, f = false;
                    ans.back().S = j;
                    //cout << j;
                    break;
                }
            }
            if (f) {
                bad = true;
            }
            //cout << endl;
            ++now;
        }
        if (bad) {
            for (int i(k - 1); i >= 0; i -= 2) {
                if ((k * (k - 1)) - k + i < int(ans.size())) {
                    swap(ans[i], ans[(k * (k - 1)) - k + i]);
                }
            }
        }

        for (auto to:ans) {
            if (!kk--) {
                break;
            }
            cout << to.F << ' ' << to.S << endl;
//            cout << "cout << " << to.F << " << ' ' << " << ' ' << to.S << " << endl;" << endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

using namespace std;
//using namespace __gnu_pbds;

#define llong long long
#define dlong long double
#define ulong unsigned long long
#define endl '\n'
#define pb push_back
#define F first
#define S second

// CODE CODE CODE CODE CODE CODE CODE CODE CODE

const llong N = 2e5  + 36;
const llong M = 1e5 + 36;
const llong INF = 2e18 + 7;
const llong MOD1 = 987654323;
const llong MOD = 1e9 + 7;
const llong MOD2 = 1e9 + 9;
const int XK[4] = {-1, 0, 1, 0};
const int YK[4] = {0, -1, 0, 1};
const int X[8] = {1, 1, -1, -1, 2, 2, -2, -2};
const int Y[8] = {2, -2, 2, -2, 1, -1, 1, -1};

//tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> st;

mt19937 gen(time(0));

set < int > st[N];
int us[N];

vector < pair < int, int > > ans;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif // LOCAL
    int n, k;
    cin >> n >> k;
    if (k % 2 == 0) {
        if (k * (k - 1) < n) {
            cout << "NO" << endl;
            return 0;
        }
        cout << "YES" << endl;
        int now = 1, lst = -1;
        for (int i(1); i <= k; ++i) {
            us[i] = 1;
        }
        while (n--) {
            cout << now << ' ';
            for (int j(us[now]); j <= k; ++j) {
                if (now != j && lst != j && !st[now].count(j)) {
                    if (us[now] == j) {
                        ++us[now];
                    }
                    st[now].insert(j);
                    lst = j;
                    cout << j;
                    break;
                }
            }
            cout << endl;
            ++now;
            if (now > k) {
                now = 1;
            }
        }
    } else {
        if (k * (k - 1) < n) {
            cout << "NO" << endl;
            return 0;
        }
        cout << "YES" << endl;
        int now = 1, lst = -1;
        for (int i(1); i <= k; ++i) {
            us[i] = 1;
        }
        while (n--) {
            ans.pb({0, k});
            ans.back().F = now;
            //cout << now << ' ';
            for (int j(us[now]); j <= k; ++j) {
                if (now != j && lst != j && !st[now].count(j)) {
                    if (us[now] == j) {
                        ++us[now];
                    }
                    st[now].insert(j);
                    lst = j;
                    ans.back().S = j;
                    //cout << j;
                    break;
                }
            }
            //cout << endl;
            ++now;
            if (now > k) {
                now = 1;
            }
        }
        for (int i(0); i < k - 1; i += 2) {
            if ((k * (k - 1)) - k + i < int(ans.size()) && k < 100000) {
                swap(ans[i], ans[(k * (k - 1)) - k + i]);
            }
        }

        for (auto to:ans) {
            cout << to.F << ' ' << to.S << endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

using namespace std;
//using namespace __gnu_pbds;

#define llong long long
#define dlong long double
#define ulong unsigned long long
#define endl '\n'
#define pb push_back
#define F first
#define S second

// CODE CODE CODE CODE CODE CODE CODE CODE CODE

const llong N = 2e5  + 36;
const llong M = 1e5 + 36;
const llong INF = 2e18 + 7;
const llong MOD1 = 987654323;
const llong MOD = 1e9 + 7;
const llong MOD2 = 1e9 + 9;
const int XK[4] = {-1, 0, 1, 0};
const int YK[4] = {0, -1, 0, 1};
const int X[8] = {1, 1, -1, -1, 2, 2, -2, -2};
const int Y[8] = {2, -2, 2, -2, 1, -1, 1, -1};

//tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> st;

mt19937 gen(time(0));

set < int > st[N];
int us[N];

vector < pair < int, int > > ans;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif // LOCAL
    int n, k;
    cin >> n >> k;
    if (k % 2 == 0) {
        if (k * (k - 1) < n) {
            cout << "NO" << endl;
            return 0;
        }
        cout << "YES" << endl;
        int now = 1, lst = -1;
        for (int i(1); i <= k; ++i) {
            us[i] = 1;
        }
        while (n--) {
            cout << now << ' ';
            for (int j(us[now]); j <= k; ++j) {
                if (now != j && lst != j && !st[now].count(j)) {
                    if (us[now] == j) {
                        ++us[now];
                    }
                    st[now].insert(j);
                    lst = j;
                    cout << j;
                    break;
                }
            }
            cout << endl;
            ++now;
            if (now > k) {
                now = 1;
            }
        }
    } else {
        if (k * (k - 1) < n) {
            cout << "NO" << endl;
            return 0;
        }
        cout << "YES" << endl;
        if (k == 3) {
            cout << 1 << ' ' <<  3 << endl;
            if (n > 1)
                cout << 2 << ' ' <<  1 << endl;
            if (n > 2)
                cout << 1 << ' ' <<  2 << endl;
            if (n > 3)
                cout << 3 << ' ' <<  1 << endl;
            if (n > 4)
                cout << 2 << ' ' <<  3 << endl;
            if (n > 5)
                cout << 3 << ' ' <<  2 << endl;
            return 0;
        }
        if (k == 5) {
            cout << 1 << ' ' <<  5 << endl;
            if (n > 1)
                cout << 2 << ' ' <<  1 << endl;
            if (n > 2)
                cout << 3 << ' ' <<  5 << endl;
            if (n > 3)
                cout << 4 << ' ' <<  1 << endl;
            if (n > 4)
                cout << 5 << ' ' <<  3 << endl;
            if (n > 5)
                cout << 2 << ' ' <<  4 << endl;
            if (n > 6)
                cout << 1 << ' ' <<  3 << endl;
            if (n > 7)
                cout << 3 << ' ' <<  1 << endl;
            if (n > 8)
                cout << 4 << ' ' <<  2 << endl;
            if (n > 9)
                cout << 5 << ' ' <<  1 << endl;
            if (n > 10)
                cout << 1 << ' ' <<  4 << endl;
            if (n > 11)
                cout << 2 << ' ' <<  3 << endl;
            if (n > 12)
                cout << 3 << ' ' <<  4 << endl;
            if (n > 13)
                cout << 4 << ' ' <<  3 << endl;
            if (n > 14)
                cout << 5 << ' ' <<  4 << endl;
            if (n > 15)
                cout << 1 << ' ' <<  2 << endl;
            if (n > 16)
                cout << 2 << ' ' <<  5 << endl;
            if (n > 17)
                cout << 3 << ' ' <<  2 << endl;
            if (n > 18)
                cout << 4 << ' ' <<  5 << endl;
            if (n > 19)
                cout << 5 << ' ' <<  2 << endl;
            return 0;
        }
        int now = 1, lst = -1;
        for (int i(1); i <= k; ++i) {
            us[i] = 1;
        }
        int kk = n, nn = n;
        bool bad = false;
        while (n > 0 || now <= k) {
            --n;
            if (now > k) {
                now = 1;
            }
            ans.pb({0, k});
            ans.back().F = now;
            //cout << now << ' ';
            bool f = true;
            for (int j(us[now]); j <= k; ++j) {
                if (now != j && lst != j && !st[now].count(j)) {
                    if (us[now] == j) {
                        ++us[now];
                    }
                    st[now].insert(j);
                    lst = j, f = false;
                    ans.back().S = j;
                    //cout << j;
                    break;
                }
            }
            if (f) {
                bad = true;
            }
            //cout << endl;
            ++now;
        }
        if (bad) {
            for (int i(k - 1); i >= 0; i -= 2) {
                if ((k * (k - 1)) - k + i < int(ans.size()) && k < 100000) {
                    swap(ans[i], ans[(k * (k - 1)) - k + i]);
                }
            }
        }

        for (auto to:ans) {
            if (!kk--) {
                break;
            }
            cout << to.F << ' ' << to.S << endl;
//            cout << "cout << " << to.F << " << ' ' << " << ' ' << to.S << " << endl;" << endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

using namespace std;
//using namespace __gnu_pbds;

#define llong long long
#define dlong long double
#define ulong unsigned long long
#define endl '\n'
#define pb push_back
#define F first
#define S second

// CODE CODE CODE CODE CODE CODE CODE CODE CODE

const llong N = 2e5  + 36;
const llong M = 1e5 + 36;
const llong INF = 2e18 + 7;
const llong MOD1 = 987654323;
const llong MOD = 1e9 + 7;
const llong MOD2 = 1e9 + 9;
const int XK[4] = {-1, 0, 1, 0};
const int YK[4] = {0, -1, 0, 1};
const int X[8] = {1, 1, -1, -1, 2, 2, -2, -2};
const int Y[8] = {2, -2, 2, -2, 1, -1, 1, -1};

//tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> st;

mt19937 gen(time(0));

set < int > st[N];
int us[N];

vector < pair < int, int > > ans;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif // LOCAL
    int n, k;
    cin >> n >> k;
    if (k % 2 == 0) {
        if (k * (k - 1) < n) {
            cout << "NO" << endl;
            return 0;
        }
        cout << "YES" << endl;
        int now = 1, lst = -1;
        for (int i(1); i <= k; ++i) {
            us[i] = 1;
        }
        while (n--) {
            cout << now << ' ';
            for (int j(us[now]); j <= k; ++j) {
                if (now != j && lst != j && !st[now].count(j)) {
                    if (us[now] == j) {
                        ++us[now];
                    }
                    st[now].insert(j);
                    lst = j;
                    cout << j;
                    break;
                }
            }
            cout << endl;
            ++now;
            if (now > k) {
                now = 1;
            }
        }
    } else {
        if (k * (k - 1) < n) {
            cout << "NO" << endl;
            return 0;
        }
        cout << "YES" << endl;
        if (k == 3) {
            cout << 1 << ' ' <<  3 << endl;
            if (n > 1)
                cout << 2 << ' ' <<  1 << endl;
            if (n > 2)
                cout << 1 << ' ' <<  2 << endl;
            if (n > 3)
                cout << 3 << ' ' <<  1 << endl;
            if (n > 4)
                cout << 2 << ' ' <<  3 << endl;
            if (n > 5)
                cout << 3 << ' ' <<  2 << endl;
            return 0;
        }
        if (k == 5) {
            cout << 1 << ' ' <<  5 << endl;
            if (n > 1)
                cout << 2 << ' ' <<  1 << endl;
            if (n > 2)
                cout << 3 << ' ' <<  5 << endl;
            if (n > 3)
                cout << 4 << ' ' <<  1 << endl;
            if (n > 4)
                cout << 5 << ' ' <<  3 << endl;
            if (n > 5)
                cout << 2 << ' ' <<  4 << endl;
            if (n > 6)
                cout << 1 << ' ' <<  3 << endl;
            if (n > 7)
                cout << 3 << ' ' <<  1 << endl;
            if (n > 8)
                cout << 4 << ' ' <<  2 << endl;
            if (n > 9)
                cout << 5 << ' ' <<  1 << endl;
            if (n > 10)
                cout << 1 << ' ' <<  4 << endl;
            if (n > 11)
                cout << 2 << ' ' <<  3 << endl;
            if (n > 12)
                cout << 3 << ' ' <<  4 << endl;
            if (n > 13)
                cout << 4 << ' ' <<  3 << endl;
            if (n > 14)
                cout << 5 << ' ' <<  4 << endl;
            if (n > 15)
                cout << 1 << ' ' <<  2 << endl;
            if (n > 16)
                cout << 2 << ' ' <<  5 << endl;
            if (n > 17)
                cout << 3 << ' ' <<  2 << endl;
            if (n > 18)
                cout << 4 << ' ' <<  5 << endl;
            if (n > 19)
                cout << 5 << ' ' <<  2 << endl;
            return 0;
        }
        int now = 1, lst = -1;
        for (int i(1); i <= k; ++i) {
            us[i] = 1;
        }
        int kk = n, nn = n;
        bool bad = false;
        while (n > 0 || now <= k) {
            --n;
            if (now > k) {
                now = 1;
            }
            ans.pb({0, k});
            ans.back().F = now;
            //cout << now << ' ';
            bool f = true;
            for (int j(us[now]); j <= k; ++j) {
                if (now != j && lst != j && !st[now].count(j)) {
                    if (us[now] == j) {
                        ++us[now];
                    }
                    st[now].insert(j);
                    lst = j, f = false;
                    ans.back().S = j;
                    //cout << j;
                    break;
                }
            }
            if (f) {
                bad = true;
            }
            //cout << endl;
            ++now;
        }
        if (bad) {
            for (int i(k - 1); i >= 0; i -= 2) {
                if ((k * (k - 1)) - k + i < int(ans.size())) {
                    swap(ans[i], ans[(k * (k - 1)) - k + i]);
                }
            }
        }

        for (auto to:ans) {
            if (!kk--) {
                break;
            }
            cout << to.F << ' ' << to.S << endl;
//            cout << "cout << " << to.F << " << ' ' << " << ' ' << to.S << " << endl;" << endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
#define fi first
#define se second
#define show(x) cout << #x << " is " << x << "\n";
const ll inf = 2e18;
const ll mod = 1e9 + 7;
const ld pi = 3.141592653589793238462643383279502884;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}
ll power(ll x, ll y){
    if(y<=0) return 1;
    ll ans = 1;
    x %= mod;
    while(y){
        if(y&1)
            ans = (x * ans) % mod;
        x = (x * x) % mod;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {return power(n, mod-2);}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = (a - b); if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = (a + b); if(c >= mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

//------------------------------------------------------------------------------------------

//const ll N = 2e5 + 1;
//vector<ll> adj[N];
//bool visited[N];

int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    cout<<fixed<<setprecision(10);

    ll n, k;
    cin>>n>>k;
    if(n>(k*(k-1))) cout<<"NO";
    else{
        cout<<"YES\n";
        ll fi=1;
        while(n>0){
            ll op = fi;
            for(int j=1;j<op && n>0;j++){
                cout<<j<<" "<<fi<<"\n";
                n--;
                if(n>0)
                    cout<<fi<<" "<<j<<"\n";
                n--;
            }
            fi++;
        }
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
#define fi first
#define se second
#define show(x) cout << #x << " is " << x << "\n";
const ll inf = 2e18;
const ll mod = 1e9 + 7;
const ld pi = 3.141592653589793238462643383279502884;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}
ll power(ll x, ll y){
    if(y<=0) return 1;
    ll ans = 1;
    x %= mod;
    while(y){
        if(y&1)
            ans = (x * ans) % mod;
        x = (x * x) % mod;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {return power(n, mod-2);}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = (a - b); if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = (a + b); if(c >= mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

//------------------------------------------------------------------------------------------

//const ll N = 2e5 + 1;
//vector<ll> adj[N];
//bool visited[N];

int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    cout<<fixed<<setprecision(10);

    ll n, k;
    cin>>n>>k;
    if(n>((k*(k+1))/2)) cout<<"NO";
    else{
        cout<<"YES\n";
        ll fi=1;
        while(n>0){
            ll op = fi;
            for(int j=1;j<op && n>0;j++){
                cout<<j<<" "<<fi<<"\n";
                cout<<fi<<" "<<j<<"\n";
                n-=2;
            }
            fi++;
        }
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
#define fi first
#define se second
#define show(x) cout << #x << " is " << x << "\n";
const ll inf = 2e18;
const ll mod = 1e9 + 7;
const ld pi = 3.141592653589793238462643383279502884;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}
ll power(ll x, ll y){
    if(y<=0) return 1;
    ll ans = 1;
    x %= mod;
    while(y){
        if(y&1)
            ans = (x * ans) % mod;
        x = (x * x) % mod;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {return power(n, mod-2);}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = (a - b); if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = (a + b); if(c >= mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

//------------------------------------------------------------------------------------------

//const ll N = 2e5 + 1;
//vector<ll> adj[N];
//bool visited[N];

int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    cout<<fixed<<setprecision(10);

    ll n, k;
    cin>>n>>k;
    if(n>(k*(k+1))) cout<<"NO";
    else{
        cout<<"YES\n";
        ll fi=1;
        while(n>0){
            ll op = fi;
            for(int j=1;j<op && n>0;j++){
                cout<<j<<" "<<fi<<"\n";
                n--;
                if(n>0)
                    cout<<fi<<" "<<j<<"\n";
                n--;
            }
            fi++;
        }
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
#define fi first
#define se second
#define show(x) cout << #x << " is " << x << "\n";
const ll inf = 2e18;
const ll mod = 1e9 + 7;
const ld pi = 3.141592653589793238462643383279502884;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}
ll power(ll x, ll y){
    if(y<=0) return 1;
    ll ans = 1;
    x %= mod;
    while(y){
        if(y&1)
            ans = (x * ans) % mod;
        x = (x * x) % mod;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {return power(n, mod-2);}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = (a - b); if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = (a + b); if(c >= mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

//------------------------------------------------------------------------------------------

//const ll N = 2e5 + 1;
//vector<ll> adj[N];
//bool visited[N];

int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    cout<<fixed<<setprecision(10);

    ll n, k;
    cin>>n>>k;
    if(n>((k*(k+1))/2)) cout<<"NO";
    else{
        cout<<"YES\n";
        ll fi=1;
        while(n>0){
            ll op = fi;
            for(int j=1;j<op && n>0;j++){
                cout<<j<<" "<<fi<<"\n";
                n--;
                if(n>0)
                    cout<<fi<<" "<<j<<"\n";
                n--;
            }
            fi++;
        }
    }

    return 0;
}


/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;*/
#include<algorithm>
#include <bits/stdc++.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define S second
#define F first
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define fb(i,n) for(ll i=n-1;i>=0;i--)
#define fb1(i,n) for(ll i=n;i>0;i--)
#define endd cout<<'\n';
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define fr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define all(x) x.begin(), x.end()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<ll>
#define pii pair<ll,ll>
#define CASES  ll t;cin>>t;while(t--)
typedef long long ll;
typedef unsigned long long ull;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
//*X.find_by_order()
//X.order_of_key()
ll mod=1000000007;
int main()
{
fast;
    ll n,k;
    cin>>n>>k;
    if(n>k*(k+1))
    {
        cout<<"No";
    }
    else
    {
        cout<<"Yes\n";
        ll c=0;
        f(i,n)
        {

            if(i%k==0)
            {
                c++;
            }
            cout<<i%k+1<<' '<<(c+i)%k+1;
            endd;
        }
    }
}


/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;*/
#include<algorithm>
#include <bits/stdc++.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define S second
#define F first
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define fb(i,n) for(ll i=n-1;i>=0;i--)
#define fb1(i,n) for(ll i=n;i>0;i--)
#define endd cout<<'\n';
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define fr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define all(x) x.begin(), x.end()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<ll>
#define pii pair<ll,ll>
#define CASES  ll t;cin>>t;while(t--)
typedef long long ll;
typedef unsigned long long ull;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
//*X.find_by_order()
//X.order_of_key()
ll mod=1000000007;
int main()
{
fast;
    ll n,k;
    cin>>n>>k;
    if(n>k*(k-1))
    {
        cout<<"No";
    }
    else
    {
        cout<<"Yes\n";
        ll c=0;
        f(i,n)
        {
            if(i%k==0)
            {
                c++;
            }
            cout<<i%k+1<<' '<<(c+i)%k+1;
            endd;
        }
    }
}


/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;*/
#include<algorithm>
#include <bits/stdc++.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define S second
#define F first
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define fb(i,n) for(ll i=n-1;i>=0;i--)
#define fb1(i,n) for(ll i=n;i>0;i--)
#define endd cout<<'\n';
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define fr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define all(x) x.begin(), x.end()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<ll>
#define pii pair<ll,ll>
#define CASES  ll t;cin>>t;while(t--)
typedef long long ll;
typedef unsigned long long ull;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
//*X.find_by_order()
//X.order_of_key()
ll mod=1000000007;
int main()
{
fast;
    ll n,k;
    cin>>n>>k;
    if(n>k*(k+1))
    {
        cout<<"No";
    }
    else
    {
        cout<<"Yes\n";
        f1(i,n)
        {
            if(i%k==0)
                cout<<k<<' ';
            else
            {
                cout<<i%k<<' ';
            }
            if((i+1)%k==0)
            {
                cout<<k;
            }
            else
            {
                cout<<(i+1)%k;
            }
            endd;
        }
    }
}


/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;*/
#include<algorithm>
#include <bits/stdc++.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define S second
#define F first
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define fb(i,n) for(ll i=n-1;i>=0;i--)
#define fb1(i,n) for(ll i=n;i>0;i--)
#define endd cout<<'\n';
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define fr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define all(x) x.begin(), x.end()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<ll>
#define pii pair<ll,ll>
#define CASES  ll t;cin>>t;while(t--)
typedef long long ll;
typedef unsigned long long ull;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
//*X.find_by_order()
//X.order_of_key()
ll mod=1000000007;
int main()
{
fast;
    ll n,k;
    cin>>n>>k;
    if(n>k*(k-1))
    {
        cout<<"No";
    }
    else
    {
        cout<<"Yes\n";
        ll c=0;
        f(i,n)
        {
            if(i%k==0)
            {
                c++;
            }
            cout<<i%k+1<<' '<<(c+i%k)%k+1;
            endd;
        }
    }
}


/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;*/
#include<algorithm>
#include <bits/stdc++.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define S second
#define F first
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define fb(i,n) for(ll i=n-1;i>=0;i--)
#define fb1(i,n) for(ll i=n;i>0;i--)
#define endd cout<<'\n';
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define fr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define all(x) x.begin(), x.end()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<ll>
#define pii pair<ll,ll>
#define CASES  ll t;cin>>t;while(t--)
typedef long long ll;
typedef unsigned long long ull;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
//*X.find_by_order()
//X.order_of_key()
ll mod=1000000007;
int main()
{
fast;
    ll n,k;
    cin>>n>>k;
    if(n>k*(k+1))
    {
        cout<<"No";
    }
    else
    {
        cout<<"Yes\n";
        ll c=0;
        f(i,n)
        {

            if(i%k==0)
            {
                c++;
            }
            cout<<i%k+1<<' '<<(c+i%k)%k+1;
            endd;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define ll long long
#define maxn 300005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
const int mod=1e9+7;
int main(){
	int n,m;
	while(cin>>m>>n){
		ll ans = n*(n-1);
		if(ans<m){
			cout<<"NO"<<endl;
			exit(0);
		}
		cout<<"YES"<<endl;
		for(int i=1;i<n;i++){
			for(int j=i+1;j<=n;j++){
				cout<<i<<' '<<j<<'\n';
				m--;
				if(!m)exit(0);
				cout<<j<<' '<<i<<'\n';
				m--;
				if(!m)exit(0);
			}
		}
	}
}


#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define ll long long
#define maxn 300005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
const int mod=1e9+7;
int main(){
	ll n,m;
	while(cin>>m>>n){
		ll ans = n*(n-1);
		if(ans<m){
			cout<<"NO"<<endl;
			exit(0);
		}
		cout<<"YES"<<endl;
		for(int i=1;i<n;i++){
			for(int j=i+1;j<=n;j++){
				cout<<i<<' '<<j<<'\n';
				m--;
				if(!m)exit(0);
				cout<<j<<' '<<i<<'\n';
				m--;
				if(!m)exit(0);
			}
		}
	}
}


#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define ll long long
#define maxn 300005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
const int mod=1e9+7;
int main(){
	ll n,m;
	while(cin>>m>>n){
		ll ans = n*(n-1);
		if(ans<m){
			cout<<"NO"<<endl;
			exit(0);
		}
		int aaa;
		cout<<"YES"<<endl;
		for(int i=1;i<n;i++){
			for(int j=i+1;j<=n;j++){
				cout<<i<<' '<<j<<'\n';
				m--;
				if(!m)exit(0);
				cout<<j<<' '<<i<<'\n';
				m--;
				if(!m)exit(0);
			}
		}
	}
}


#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define ll long long
#define maxn 300005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
const int mod=1e9+7;
int main(){
	int n,m;
	while(cin>>n>>m){
		ll cnt=0;
		for(int i=m-1;i>0;i--){
			cnt+=i;
		}
		cnt<<=1;
		if(cnt<n){
			cout<<"NO"<<endl;
		}
		else{
			cout<<"YES"<<endl;
			cnt=0;
			int gp=1;
			while(1){
				for(int i=1;i<=m-gp;i++){
					cout<<i<<' '<<i+gp<<endl;
					cnt++;
					if(cnt==n){
						exit(0);
					}
				}
				for(int i=m-gp;i>=1;i--){
					cout<<i+gp<<' '<<i<<endl;
					cnt++;
					if(cnt==n){
						exit(0);
					}
				}
				gp++;
			}
		}
	}
}


#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define ll long long
#define maxn 300005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
const int mod=1e9+7;
int main(){
	int n,m;
	while(cin>>n>>m){
		ll cnt=0;
		for(int i=m-1;i>0;i--){
			cnt+=i;
		}
		cnt<<=1;
		if(cnt<n){
			cout<<"NO"<<endl;
		}
		else{
			cout<<"YES"<<endl;
			cnt=0;
			int gp=1;
			while(1){
				for(int i=1;i<=n-gp;i++){
					cout<<i<<' '<<i+gp<<endl;
					cnt++;
					if(cnt==n){
						exit(0);
					}
				}
				for(int i=n-gp;i>=1;i--){
					cout<<i+gp<<' '<<i<<endl;
					cnt++;
					if(cnt==n){
						exit(0);
					}
				}
				gp++;
			}
		}
	}
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <sstream>
#include <cmath>
#include <tuple>
#include <limits>

#define ll long long
#define ull unsigned long long
#define ci cin
#define co cout
#define cl endl
#define ii pair<int,int>
#define iii tuple<int,int,int>
#define mp(i,j) make_pair(i,j)
#define mt(i,j,k) make_tuple(i,j,k)
#define mpq priority_queue<int,vector<int>,greater<int>>
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define vs vector<string>
#define vd vector<double>
#define vii vector<pair<int,int>>
#define vdd vector<pair<double,double>>
#define vvii vector<vector<pair<int,int>>>
#define pb(i) push_back(i)
#define pf(i) push_front(i)
#define ppb() pop_back()
#define ppf() pop_front()
#define sz() size()
#define bk() back()
#define ft() front()
#define fs first
#define sc second
#define max(i,j) ((i>j)?(i):(j))
#define min(i,j) ((i<j)?(i):(j))
#define rvs(i) reverse(i.begin(),i.end())
#define rvsc(i,c) reverse(i.begin(),i.begin()+c)
#define ssort(i) sort(i.begin(),i.end())
#define ers erase
#define ins insert
#define bgn begin
#define clr clear
#define asn assign
#define gln(s) getline(cin,s)
#define rep(i,n) \
  for(int i=0;i<n;++i)
#define repc(i,c,n) \
  for(int i=c;i<n;++i)
#define repr(i,c,n) \
  for(int i=c;i>=n;--i)
#define inf (2147483647/2)
#define pi 3.141592653589793
#define eps 0.00000000001
#define lwb lower_bound

using namespace std;

int main(){
  int n,k;
  ci>>n>>k;
  int b=0,g=0;
  vii res;
  repc(i,1,k)repc(j,1,k){
    int tb=j,tg=j+i;
    if(tg>k) break;
    if(b==tb) swap(tb,tg);
    b=tg;g=tb;
    res.pb(mp(tb,tg));
    res.pb(mp(tg,tb));
    if(res.sz()==n) goto ret;
  }
  ret:
  if(res.sz()==n){
    co<<"YES"<<cl;
    for(auto& p:res)
      co<<p.fs<<" "<<p.sc<<cl;
  }else{
    co<<"NO"<<cl;
  }
  return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <sstream>
#include <cmath>
#include <tuple>
#include <limits>

#define ll long long
#define ull unsigned long long
#define ci cin
#define co cout
#define cl endl
#define ii pair<int,int>
#define iii tuple<int,int,int>
#define mp(i,j) make_pair(i,j)
#define mt(i,j,k) make_tuple(i,j,k)
#define mpq priority_queue<int,vector<int>,greater<int>>
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define vs vector<string>
#define vd vector<double>
#define vii vector<pair<int,int>>
#define vdd vector<pair<double,double>>
#define vvii vector<vector<pair<int,int>>>
#define pb(i) push_back(i)
#define pf(i) push_front(i)
#define ppb() pop_back()
#define ppf() pop_front()
#define sz() size()
#define bk() back()
#define ft() front()
#define fs first
#define sc second
#define max(i,j) ((i>j)?(i):(j))
#define min(i,j) ((i<j)?(i):(j))
#define rvs(i) reverse(i.begin(),i.end())
#define rvsc(i,c) reverse(i.begin(),i.begin()+c)
#define ssort(i) sort(i.begin(),i.end())
#define ers erase
#define ins insert
#define bgn begin
#define clr clear
#define asn assign
#define gln(s) getline(cin,s)
#define rep(i,n) \
  for(int i=0;i<n;++i)
#define repc(i,c,n) \
  for(int i=c;i<n;++i)
#define repr(i,c,n) \
  for(int i=c;i>=n;--i)
#define inf (2147483647/2)
#define pi 3.141592653589793
#define eps 0.00000000001
#define lwb lower_bound

using namespace std;

int main(){
  int n,k;
  ci>>n>>k;
  int b=0,g=0;
  vii res;
  repc(i,1,k)repc(j,1,k){
    int tb=j,tg=j+i;
    if(tg>k) break;
    if(b==tb) swap(tb,tg);
    b=tb;g=tg;
    res.pb(mp(b,g));
    if(res.sz()==n) goto ret;
  }
  ret:
  if(res.sz()==n){
    co<<"YES"<<cl;
    for(auto& p:res)
      co<<p.fs<<" "<<p.sc<<cl;
  }else{
    co<<"NO"<<cl;
  }
  return 0;
}